Tuesday, 27 September 2016

TabLayout (Android Design Library) Text Color

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Below will reference with our custom style -->
    <item name="android:textAppearance">@style/my_tab_text</item>
</style>

<style name="my_tab_text" parent="Base.TextAppearance.AppCompat">
    <item name="android:textColor">@android:color/holo_blue_dark</item>
</style>
And if you dont want to reference from your Apptheme you can directly specify to TabLayout using Below snippet.
 <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabTextAppearance="@style/my_tab_text"
            app:tabIndicatorHeight="48dp"/>

Friday, 23 September 2016

Android google map zooming and running the current location

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

package com.example.location;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

public class LocationActivity extends SherlockFragmentActivity implements LocationListener     {
private GoogleMap map;
private LocationManager locationManager;
private static final long MIN_TIME = 400;
private static final float MIN_DISTANCE = 1000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, this); //You can also use LocationManager.GPS_PROVIDER and LocationManager.PASSIVE_PROVIDER        
}

@Override
public void onLocationChanged(Location location) {
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
    map.animateCamera(cameraUpdate);
    locationManager.removeUpdates(this);
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) { }

@Override
public void onProviderEnabled(String provider) { }

@Override
public void onProviderDisabled(String provider) { }
}

map.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
if you need zooming effect very close 
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
  
/*   CameraPosition cameraPosition = new CameraPosition.Builder()
      .target(latLng).zoom(19f).tilt(70).build();
   googleMap.setMyLocationEnabled(true);
      googleMap.animateCamera(CameraUpdateFactory
              .newCameraPosition(cameraPosition));*/










Tuesday, 19 July 2016

Custom Kestore to upload signed APK for Playstore using SHA1

Usually when  create the google map it will run proper in locally after setting google key ,package name and SHA1 certificate fingerprint

when upload the APK to play store we have to create custom keystore, then only we will be able to upload playstore
 here when change the keystore default into custom obviously SHA1 fingerprint also will get changed
so we have to try change in eclipse


here or we can try

C:\Users\**********>keytool -list -keystore D:\APK\Keystore\oneapp.keystore
Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

oneapp, Jul 19, 2016, PrivateKeyEntry,
Certificate fingerprint (SHA1): CF:64:96:E5:A9:F9:EF:70:6F:7D:18:2B:54:36:E5:7D:
A8:5F:7A:99







There is other way of doing as follow here


Steps (for ADT):
1.Export any project (It will show you an option to create custom keystore).
enter image description here
create your keystore with an extention ".keystore" and give password android and press next.
2.enter image description here
give alias name = androiddebugkey and password = android
now press finish and your keystore is ready.
1.Go to windows -> preference
and give the path of your custom keystore file
enter image description here





Monday, 7 December 2015

Android/SCREEN ON, SCREEN OFF BroadcastReceiver

public class MyApplication extends Application {
    public static final String TAG = "SCREEN";
 
    private BroadcastReceiver scrOnReceiver;
    private BroadcastReceiver scrOffReceiver;
    private IntentFilter scrOnFilter;
    private IntentFilter scrOffFilter;
 
    @Override
    public void onCreate() {
        super.onCreate();
 
        scrOnReceiver = new BroadcastReceiver() { 
            @Override 
            public void onReceive(Context context, Intent intent) { 
                Log.d(TAG, "SCREEN ON"); 
  timer.cancel();
            } 
        };
 
        scrOnFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); 
 
        scrOffReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d(TAG, "SCREEN OFF");
  timer.start();
            }
        };
 
        scrOffFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
 
        registerReceiver(scrOnReceiver, scrOnFilter);
        registerReceiver(scrOffReceiver, scrOffFilter);
    }

//time counting
 CountDownTimer timer = new CountDownTimer(1*60*1000, 1000) {

        public void onTick(long millisUntilFinished) {
           //Some code
         Log.d("timer", "--"+millisUntilFinished);
         
        }

        public void onFinish() {
           //Logout
         Intent intent=new Intent(AppController.this,LoginActivity.class);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

         Log.d("***********", "logout");
        }
     };
 
    @Override
    public void onTerminate() {
        super.onTerminate();
 
        unregisterReceiver(scrOnReceiver);
        unregisterReceiver(scrOffReceiver);
    }
 
}




<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
 
    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
   </application>

Tuesday, 24 November 2015

Android application logout after 15 min

Here i just made the code the application should come out when it is not used till 15 minutes

for counting i have taken counter


CountDownTimer timer = new CountDownTimer(15 *60 * 1000, 1000) {

       public void onTick(long millisUntilFinished) {
          //Some code
        Log.d("timer", "--"+millisUntilFinished);
       }

       public void onFinish() {
          //Logout
        finish();
        Log.d("***********", "logout");
       }
    };


then i just calling the timer when it goes to sleep

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d("***********", "onPause");
timer.start();
}



meanwhile if the application started again it means like resume, it should cancel

 @Override protected void onResume()
{ Log.d("***********", "onresume");
 super.onResume(); timer.cancel();
 }