How to push project source code to BitBucket repository from Android Studio

Hi Guys, In this post, I’ll give details about push project source code to Bitbucket repository from Android Studio.

When you started working on a project in Android Studio, you may want to store the project code to safe remote server. For this purpose its recommended to use Bitbucket repository system. Which will allow you to create repository and push all source code safely. Important feature it’ll provide you all Git features with Project management system. So you can create Multiple branches and Tags and manage your source code safely even with multiple developers working on a same project.

You need to have BitBucket Login for creating new repository, If you not have you can create a Bitbucket login here. After creating Account, Login to BitBucket website and Create a new repository. And get the link for new repository. It’ll be used in Android Studio later.

Ok, Now Open Android Studio with your project source code. Go through the below steps to Push project.

In Android Studio, Go to VCS menu -> Select Enable Version Control Integration…

project source code

You’ll see Popup to select version Control System. here select Git and click OK.

You’ll see your Project files changes to orange colour.

Now right click Project, it will display a menu. Goto Git->Select Add

After clicking on Add, Project files will change to green colour

Now Again right click on Project and in menu Go to Git-> Select Commit Directory…

It’ll display a Commit Changes dialog, Enter your Commit Message and click Commit.

Now right Click on Project Source Code, in menu Go to Git-> Select Repository -> and then Select Push… or else you can type shortcut keys¬†Ctrl+Shift+K .

You’ll Push Commits dialog, In this dialog you’ll see master –> Define Remote.

Click on Define Remote, It’ll display a Define Remote dialog. In this dialog paste the URL(that is taken in Bitbucket after creating repository). And click OK.

It’ll show all the Committed files and message you entered before when committing directory. Now Click on Push. It’ll push all code files to Bitbucket repository.

Now if you go to bitbucket website in a browser and open your repository and refresh it. You’ll see project source code pushed safely to your repository.

That’s it.

Hope it helps somebody.

ūüí°

 

 

 

 

 

 

How to disable Auto Correction to avoid wrong input when typing text Messages in Android Phone

At times, when you chatting with your friends in your local language using English text. You may see typed text is Auto corrected to some English vocabulary text, which will change whole meaning of the message. You may wonder about the wrong sent message. It’s due to Auto Correction feature in Phone Keyboard settings which is turn ON¬†by default.

Simple reasons for disable Auto Correction

I’ve seen many of my friends get annoyed with this Auto Correction feature in Android Phone. Its useful if you type a good English text. But when you typing local language in English then you may feel bad if any wrong message is sent over by this Auto Correction feature. And also you have to be cautious before sending message itself, to recheck typed text whether it has your heartfelt text or its changed to something else. etc

To avoid this problem, Its always better to disable auto correction for typing in phone. Below gives details for disable Auto correction text.

Solution:

Go to Settings -> Language & Input

Auto Correction

Now Select Virtual Keyboard

language2

Select Gboard

language3

Now Select Text Correction

language4

here you’ll see Auto-Correction is turned ON.

language5

Just click on it to turn it Off.

That’s it. Now next time on wards you can type your messages freely without any worry about auto text correction.

Hope it helps somebody

(Given Images are on Moto G4 Plus, Android Nougat version.)

You may be also interested in

How to make EditText not editable but scrollable

EditText not Editable but Scrollable

When we need to show long text like Terms and conditions in EditText. We need to allow scrolling and it should not be editable.

Editable

For this I tried in XML set EditText attributes to show vertical scrollbars

android:scrollbars="vertical"

And then to make EditText not editable i tried different ways like

android:inputType="none"

not worked, and also tried

android:Editable=false

but it is deprecated.

And then tried this line in code

editTextView.setEnabled(false);

Its not allowed to Edit. But unable scroll text in EditText.

Solution:

And Finally i found the work around for it. Added this line in code.

editTextView.setKeyListener(null);

It worked perfectly….

Hope this helps somebody….

You may be also interested in

 

Html tags in Text not working in TextView

Here I try to explain the details why Html tags in Text not working in TextView.¬†At times you may need to display text with Bold and normal style in TextView like this, ¬†…(You may¬†skip to solution¬†)

Html Tags in Text

Welcome, to your favorite music app store.   

So, you’ll define a string in string.xml file as follows

<string name="welcome_text"><b>Welcome,</b> to your favorite music app store.</string>

You’ll apply this wecome_text in a TextView in Java code as below.

TextView tvWelcomeUser=(TextView)findViewById(R.id.tvWelcome);
tvWelcomeUser.setText(R.string.welcome_text);

If you apply setText(int resID) as shown above you can see the text in TextView as expected “Welcome,¬†to your favorite music app store.”

But if you like to display dynamically generated text after Welcome message, as shown below

Welcome, to your favorite music app store. Logged in as: <username>

here <username> is dynamically generated text. You can do this in two ways,

One way is concatenate dynamic text using “+” symol

tvWelcomeUser.setText(getString(R.string.welcome_text) + " Logged in as:" + username);

Another way is defining string in strings.xml file

//in string.xml file
<string name="welcome_text"><b>Welcome,</b> to your favorite music app store. Logged in as: %1$s.</string>

You’ll assign to TextView in Java code like this

//and in Java code
tvWelcomeUser.setText(String.format(getString(R.string.welcome_text),username));

Here comes the issue, In both ways you’ll miss bold text for Welcome text.

even if you try this Html.fromSting(string) method it wont work.

//and in Java code
tvWelcomeUser.setText(Html.fromHtml(String.format(getString(R.string.welcome_text),username)));

You may wondering about this issue, why its not working suddenly which worked before. The reason for this issue is you are converting to String which ignores html tags.

Html tags in Text not working in TextView Solution:

The only solution for this issue is using CData sections for the string in strings.xml file as shown below

//in string.xml file
<string name="welcome_text"><![CDATA[<b>Welcome,</b> to your favorite music app store. Logged in as:]]> %1$s.</string>

Now in Java code you can assign like this,

//and in Java code
String welcomStr=String.format(getString(R.string.welcome_text),username);
tvWelcomeUser.setText(Html.fromHtml(welcomStr));

CData section in string text keeps the html tag data intact even after formatting text using String.format method. So, Html.fromHtml(str) works fine and you’ll see the bold text in Welcome¬†message.

Welcome, to your favorite music app store. Logged in as: <username>

It displays bold text as expected. horray… ūüôā

Hope it helps somebody… ūüėé

You may be also interested in

 

Simple Weekview calendar implemented using GridView

Simple Weekview calendar implemented using GridView.

I tried to search for a simple Weekview calendar, which display 7 week days. But not able to find a simple one. So i implemented simple weekview calendar which just displays 7 week days with left right buttons to load prev/next week days.

Screenshot

Weekview calendar

Simple Weekview calendar implemented using GridView.

Download source code from this link.

Hope it helps somebody.

You may be also interested in..

Flash or Pulse Animation for a Button Android

At times we may require to get user’s attention to click on a Button, to view some important information in app. For this purpose Flash or Pulse animation helps us very well. Below are code snippets to implement these animations.

Implementing Flash animation

We can use AnimationDrawable class, to add frames of two different colours, which produces flash animation. Below is an example code.

Here im displaying rounded shape button, so i used RoundRectShape class, given radii as argument. If you want a rectangle shape, just replace radii withnull

AnimationDrawable adBtn;

private void applyFlashBackgroundAnimation(){
     float[] radii = new float[8];
     radii[0] = getResources().getDimension(R.dimen.spacing_10);
     radii[1] = getResources().getDimension(R.dimen.spacing_10);
     radii[2] = getResources().getDimension(R.dimen.spacing_10);
     radii[3] = getResources().getDimension(R.dimen.spacing_10);

     radii[4] = getResources().getDimension(R.dimen.spacing_10);
     radii[5] = getResources().getDimension(R.dimen.spacing_10);
     radii[6] = getResources().getDimension(R.dimen.spacing_10);
     radii[7] = getResources().getDimension(R.dimen.spacing_10);
     ShapeDrawable selShape = new ShapeDrawable();
     selShape.setShape(new RoundRectShape(radii, null, null));
     selShape.getPaint().setColor(Color.GREEN);

     ShapeDrawable defShape = new ShapeDrawable();
     defShape.setShape(new RoundRectShape(radii, null, null));
     defShape.getPaint().setColor(Color.GRAY);
     
     adBtn = new AnimationDrawable();
     adBtn.addFrame(selShape, DELAY);
     adBtn.addFrame(defShape, DELAY);
     adBtn.setOneShot(false);
     btnObj.setBackgroundDrawable(adPick);//btnObj is your Button object
     Handler handler== new Handler();
     handler.postDelayed(new Runnable() {
         @Override
          public void run() {
              adBtn.start();
          }
     }, 100);
}

//To Stop Animation, simply use stop method of AnimationDrawable object as below.
private void stopFlashAnimation()
    adBtn.stop();
}

Implementing Pulse animation

To produce Pulse or Heartbeat animation, we use ObjectAnimator class. Below is the example code.

ObjectAnimator objAnim;
private void pulseAnimation(){
    objAnim= ObjectAnimator.ofPropertyValuesHolder(btnObj, PropertyValuesHolder.ofFloat("scaleX", 1.5f), PropertyValuesHolder.ofFloat("scaleY", 1.5f));
    objAnim.setDuration(300);
    objAnim.setRepeatCount(ObjectAnimator.INFINITE);
    objAnim.setRepeatMode(ObjectAnimator.REVERSE);
    objAnim.start();
}

//To Stop Animation, simply use cancel method of ObjectAnimator object as below.

private void stopPulseAnimation()
    objAnim.cancel();
}

That’s it.

Hope it helps somebody… ūüôā

You may also interested in..

Create Rounded Shapes to apply Button background dynamically

Create Rounded Shapes with colours, and apply Button stateslist as background dynamically

While working on applying dynamic themes to app screens, I happen to work on applying Rounded Shapes with the colours dynamically, to display button states (i.e. default, pressed or focused etc) and also Text colors based on the colour codes in API response.

Rounded Shapesrounded_gray

below is the sample XML API response which shows color codes and XML data.

XML Color codes

 <!-- sample xml data -->
<DefBtnColour>#24014c</DefBtnColour>
<SelBtnColour>#5656ff</SelBtnColour>
<DefBtnFontColour>#afdbb6</DefBtnFontColour>
<SelBtnFontColour>#aa0197</SelBtnFontColour>

Applying shapes and button colour states is easy by creating a selector xml file in drawable folder. but applying dynamically need some more insight to implement in code.

Here is the code snippet… for it

First implemented two rounded shapes with <DefBtnColour> and <SelBtnColour> colours data, using ShapeDrawable class.

Rounded Shapes drawables using ShapeDrawable class

float[] radii = new float[8];
radii[0] = getResources().getDimension(R.dimen.spacing_10); //spacing_10 is 10dp
radii[1] = getResources().getDimension(R.dimen.spacing_10);
radii[2] = getResources().getDimension(R.dimen.spacing_10);
radii[3] = getResources().getDimension(R.dimen.spacing_10);

radii[4] = getResources().getDimension(R.dimen.spacing_10);
radii[5] = getResources().getDimension(R.dimen.spacing_10);
radii[6] = getResources().getDimension(R.dimen.spacing_10);
radii[7] = getResources().getDimension(R.dimen.spacing_10);

ShapeDrawable selShape = new ShapeDrawable();
selShape.setShape(new RoundRectShape(radii, null, null));
selShape.getPaint().setColor(selectedColour);

ShapeDrawable defShape = new ShapeDrawable();
defShape.setShape(new RoundRectShape(radii, null, null));
defShape.getPaint().setColor(defaultcolour);

now add these shapes to the StateListDrawable for default and pressed states..

StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] {android.R.attr.state_pressed}, selShape);
stateListDrawable.addState(new int[] {}, defShape);

now you can return this stateListDrawable object to apply button background drawable.

whole code snippets is below

 //step 1
protected StateListDrawable applyButtonSelector(int defaultcolour,int selectedColour){
    float[] radii = new float[8];
    radii[0] = getResources().getDimension(R.dimen.spacing_10);
    radii[1] = getResources().getDimension(R.dimen.spacing_10);
    radii[2] = getResources().getDimension(R.dimen.spacing_10);
    radii[3] = getResources().getDimension(R.dimen.spacing_10);

    radii[4] = getResources().getDimension(R.dimen.spacing_10);
    radii[5] = getResources().getDimension(R.dimen.spacing_10);
    radii[6] = getResources().getDimension(R.dimen.spacing_10);
    radii[7] = getResources().getDimension(R.dimen.spacing_10);

    ShapeDrawable selShape = new ShapeDrawable();
    selShape.setShape(new RoundRectShape(radii, null, null));
    selShape.getPaint().setColor(selectedColour);

    ShapeDrawable defShape = new ShapeDrawable();
    defShape.setShape(new RoundRectShape(radii, null, null));
    defShape.getPaint().setColor(defaultcolour);

    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] {android.R.attr.state_pressed}, selShape);
    stateListDrawable.addState(new int[] {}, defShape);
    return stateListDrawable;
}

apply to button background as below

//step 2
themeBtn.setBackgroundDrawable(applyButtonSelector(convertToColorInt(DefaultButtonColour), convertToColorInt(SelectedButtonColour)));

below is the code to convert response colour code text to integer colour code

public static int convertToColorInt(String argb) throws IllegalArgumentException {
   if (!argb.startsWith(HASH)) {
      argb = HASH + argb;
   }
   return Color.parseColor(argb);
}

with this code (step 1,2) you can see,  shape and states drawable applied to button dynamically.

To apply ColorStates for button text you can see this post or SO ref link.

Hope this helps somebody…

ref links: http://stackoverflow.com/a/16502692/341443
http://stackoverflow.com/a/5963179/341443

ūüôā

You may be also interested in

 

Android Studio ADB wipes out logcat quickly when app crashes

Android Studio ADB wipes out logcat quickly

At time we may face this kind of annoying issue. In Android Studio, in Android tab ADB wipes out log cat data quickly when app crashes. And makes us not able to find out the code issue.

wipes out

To solve this issue, in Android tab on right side you can see dropdown to select the log filter

logcat2

Select Edit Filter Configuration, and you will see this window

logcat3

In this window, set your application Package Name as shown in  above image. You can set any Filter Name text. and Click OK.

Now, if app crashes, it will show the log data.

Hope it helps somebody…

 

You may also interested in

Unable to resolve superclass of Activity

Unable to resolve superclass

When you added Android Support library to your project in Eclipse ADT, to implement classes like FragmentActivity, ViewPager etc At times you may see this error which results in app crash due to Unable to resolve superclass,

Unable to resolve superclass of Lin/AppPath/MainActivity; (9)
05-16 14:10:11.705: W/dalvikvm(6534): Link of class 'Lin/AppPath/MainActivity;' failed
05-16 14:10:11.705: D/AndroidRuntime(6534): Shutting down VM
05-16 14:10:11.705: W/dalvikvm(6534): threadid=1: thread exiting with uncaught exception (group=0x41ba5c08)
05-16 14:10:11.705: E/AndroidRuntime(6534): FATAL EXCEPTION: main
05-16 14:10:11.705: E/AndroidRuntime(6534): Process: , PID: 6534
05-16 14:10:11.705: E/AndroidRuntime(6534): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{/.MainActivity}: java.lang.ClassNotFoundException: Didn't find class ".MainActivity" on path: DexPathList[[zip file
......
....

There may be a chance that Android Private Library, not exported while generating API file. Due to Android Private Libraries is unchecked in Order and Export tab in Java build path dialog as shown below. resolve superclass So, just check the Android Private Libraries and Click Ok. Clean and Build the app. Fixes the issue.

private_Library1

Hope it helps somebody. ūüôā

You may be also interested in

ScrollView auto scroll to show content in app screen

While displaying long text data or displaying data in lot of views, we use ScrollView to view whole screen by scrolling. At times we may require app to auto Scroll down in a screen to show a bottom content.

If you try using below code in Activity’s OnCreate method to scroll down in ScrollView

ScrollView mScrollView = (ScrollView) findViewById(R.id.myScrollView);
mScrollView.fullScroll(ScrollView.FOCUS_DOWN);

It won’t scroll. Since the layout is not yet¬†done adding all views and¬†you call fullScroll immediately after instantiating the ScrollView.

Solution for ScrollView to auto scroll down

auto scroll

To solve this issue, A short delay gives, the system enough time to settle. You have to use following code to set the delay

mScrollView.postDelayed(new Runnable() {
    @Override
    public void run() {
       //replace this line to scroll up or down
       mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
    }
}, 100L);

voila, you can see app Scroll down to bottom of screen.

Similarly, If you want to set Scroll to top of screen, in above run() method replace line with

mScrollView.scrollTo(0, 0);

If you are using HorizotalScrollView, and if you want to move to right end of screen, use following code..

mHorizontalScrollView.postDelayed(new Runnable() {
    @Override
    public void run() {
      mHorizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
    }
}, 100L);

here mHorizontalScrollView is object of HorizantalScrollView.

Hope it helps somebody.

ūüôā

You may be also interested in