Wednesday, 8 April 2015

Copy and share your useful data from Google chrome browser to your application in android.



Here In this blog I explain that how to copy and share your useful data from chrome browser in android.

1) How to show your application in Google chrome share list ?

First in manifest.xml file you need intent-filter to show your application in share list which will be display on click of share button in Google chrome in your android device.

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleInstance">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>



Show your application in share list.(Here Blog detail)



 2) How to receive this data in activity ?
 
  Here I am display this data in DiaolgActivity So,we need to set intent-filter in manifest.xml file as show below .

    <activity
        android:name=".DiaolgActivity"
        android:label="@string/app_name"
        android:theme="@style/AppThemeDialog"
        android:launchMode="singleInstance">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="com.google.android.gm.action.AUTO_SEND" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>

In Oncreate() Method do this thing.

    if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
               String strData = intent.getStringExtra(Intent.EXTRA_TEXT);// here get data.
                Log.e("text", "- " + strData );
            } else {
                finish();
            }
        }




On Save click you can store this data in your application.

Monday, 30 June 2014

How to Install Android L on Your Nexus Device.

Now, you have to install the correct drivers for your Nexus 5 and/or Nexus 7. Here is what you need to do:

After connecting the device to the PC, power the Nexus off.
Turn on your device in fastboot mode; the key combination for your device is either volume down + power (2013 Wi-Fi Nexus 7, codenamed flo/razor) or volume up + volume down + power (Nexus 5, codenamed hammerhead).
From Device Manager (Computer -> Properties -> Device Manager) identify your device (it will show up with a yellow exclamation mark icon).
Right click on it, select Update Driver Software and then select Browse my computer for driver software.
Select Let me pick from a list of device drivers on my computer.
From Have Disk... option manually install the android_winusb.inf driver (in my case, its location is C:\Program Files (x86)\Android\android-sdk\extras\google\usb_driver). Accept any prompts that may appear.
Select the Android ADB Interface option when given the option. Accept any prompts that may appear.


Step 1: Connect Your Phone to Your PC

This is a simple, yet important step. Make sure the USB cable that you're using to connect your phone to your PC is in good condition. 

Step 2: Download the Preview Images from Google
Google has made the Android L preview images available on a special developers website, but that doesn't mean the general public can't download them too.

From your Windows PC, click this link to head to the download page. From here, scroll down a bit and click the download link next to the Nexus 5 (GSM/LTE) "hammerhead" entry (or Nexus 7 (WiFi) "razor" if you are doing this for your Nexus 7).



Step 3: Configure Nexus Root Toolkit
By now, you should have arrived at the Nexus Root Toolkit's main screen. But before you get to flashing the images, you'll need to make sure your device drivers are in order. Right up top, click the button that says Full Driver Installation Guide to begin.

Step 5: Flash the Preview Images
At this point, the only thing left to do is install the Android L preview images. From the NRT main screen, click Flash Stock + Unroot to begin.


On the following screen, tick the box next to Other/Browse up top, and make sure that I downloaded a factory image myself that I would like to use instead is selected as the second option.
               


A file browser window will pop up at this point. Just navigate to your Downloads folder and select the hammerhead...tgz file that you downloaded earlier (or the razor...tgz file for the Nexus 7).


Shortly after that, you'll be asked to enter an MD5 number to verify the file's integrity. Copy the following text, then paste it into the field in that window and click OK:

5a6ae77217978cb7b958a240c2e80b57 (this will be different for the Nexus 7)
                          

At this point, the file will be verified and extracted, so give it a minute or two. When it's done, a window will appear that summarizes the install options you've selected. Click OK here to begin flashing the update, making sure that your phone doesn't get disconnected from your PC during this process.


The process takes at least 5 minutes to complete, so don't freak out if it seems to get hung up on one aspect of the install. When it's finished, you'll get a confirmation dialog that instructs you to Press any key to exit, so do that. Close out any further dialog boxes, as you're done with the Nexus Root Toolkit.



For some reason, Android L doesn't seem to want to boot up if you're still connected to your PC. So disconnect your USB cable at this point, and give your phone at least 5 minutes to finish booting.


All Done!
Your device is now running the Android L preview. Be aware that you may encounter bugs due to it being in an earlier stage of development. 

Friday, 27 June 2014

The use of getViewTypeCount() and getItemViewType() in Adapter .

If we need to show different type of view in list-view then its good to use  getViewTypeCount() and getItemViewType() in adapter instead of  toggling a vieVIEW.GONE and VIEW.VISIBLE can be very expensive task inside getView() which will affect the list scroll.
So first of all you need to create different layouts for each type of view.

 1.simple textview.

 2.Row with image and text.


3.Simple row.


4.Row with two view .

So first need to create 4 different xmls for different row type.

Ho to use this getViewTypeCount() and getItemViewType() in adapter?
1) getViewTypeCount() :-
Returns the count of different type of views. Here we are having four different type of views so this method will return count as 4.
@Override
public int getViewTypeCount() {
return 4;
}
2) getItemViewType() :-
@Override
public int getItemViewType(int position) {

 if (mArrayList.get(position) instanceof TextModel) {
    return VIEW_TYPE_ROW_1;
 } else if (mArrayList.get(position) instanceof HeaderModel) {
    return VIEW_TYPE_ROW_2;
 } else if (mArrayList.get(position) instanceof ImageModel) {
    return VIEW_TYPE_ROW_3;
 } else {
    return VIEW_TYPE_ROW_4;
 }
}
Now Do Work inside getView(...) method first we determine the type of view by calling getItemViewType(..) method, which will return the type to be inflated as shown below.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder.MapViewHolder mapViewHolder = null;
Holder.HdrViewHolder hdrViewHolder = null;
Holder.GridViewHolder gridViewHolder = null;
Holder.BrthViewHolder brthViewHolder = null;
int type = getItemViewType(position);
if (type == VIEW_TYPE_ROW_1) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.raw_one, null);
mapViewHolder = new Holder().new MapViewHolder();
mapViewHolder.cardViewGmap = (CardView) convertView
.findViewById(R.id.list_raw_map);
convertView.setTag(mapViewHolder);
} else {
mapViewHolder = (MapViewHolder) convertView.getTag();
}
GooglePlaySmallCard cardGmap = new GooglePlaySmallCard(mContext);
cardGmap.setId("gplaysmall");
// Set card in the cardView
mapViewHolder.cardViewGmap.setCard(cardGmap);
} else if (type == VIEW_TYPE_ROW_2) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.raw_three, null);
hdrViewHolder = new Holder().new HdrViewHolder();
hdrViewHolder.cardshd = (CardView) convertView
.findViewById(R.id.list_carddemo_shadow_layout);
convertView.setTag(hdrViewHolder);
} else {
hdrViewHolder = (HdrViewHolder) convertView.getTag();
}
Card shcard = new Card(mContext);
// Create a CardHeader
CardHeader header = new CardHeader(mContext);
// Set the header title
header.setTitle(mContext.getString(R.string.demo_header_basetitle));
shcard.addCardHeader(header);
// Hidden shadow
shcard.setShadow(true);
hdrViewHolder.cardshd.setCard(shcard);
} else if (type == VIEW_TYPE_ROW_3) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.raw_two, null);
gridViewHolder = new Holder().new GridViewHolder();
gridViewHolder.gdcardView = (CardView) convertView
.findViewById(R.id.list_carddemo_Gplay1);
gridViewHolder.gdcardView1 = (CardView) convertView
.findViewById(R.id.list_carddemo_Gplay2);
convertView.setTag(gridViewHolder);
} else {
gridViewHolder = (GridViewHolder) convertView.getTag();
}
GplayCard gcard = new GplayCard(mContext);
gridViewHolder.gdcardView.setCard(gcard);
gridViewHolder.gdcardView1.setCard(gcard);
} else if (type == VIEW_TYPE_ROW_4) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_demo_raw, null);
brthViewHolder = new Holder().new BrthViewHolder();
brthViewHolder.bthcardView = (CardView) convertView
.findViewById(R.id.list_carddemo_cardBirth);
convertView.setTag(brthViewHolder);
} else {
brthViewHolder = (BrthViewHolder) convertView.getTag();
}
GoogleNowBirthCard birthCard = new GoogleNowBirthCard(mContext);
birthCard.setId("myId");
brthViewHolder.bthcardView.setCard(birthCard);
}
return convertView;
}

 Hope this is useful to someone.

Thursday, 1 May 2014

Android List view with pull to Refresh and Swipe functionality.

Here, I have a list (PullToRefreshSwipeListView) that implementing both of PullToRefresh  and SwipeListView library.
List can do some basic functionality like pullUp/pullDown and swipe left/right.

If you decide to use PullToRefreshSwipeListView as a view, you can define it in your xml layout like this:

 <com.handmark.pulltorefresh.library.PullToRefreshSwipeListView
        xmlns:swipe="http://schemas.android.com/apk/res-auto"
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@drawable/line_separator_repeat"
        android:listSelector="#00000000"
        ptr:ptrMode="pullFromEnd"
        swipe:swipeActionLeft="reveal"
        swipe:swipeBackView="@+id/back" //raw back view
        swipe:swipeCloseAllItemsWhenMoveList="true"
        swipe:swipeFrontView="@+id/front" // raw front view
        swipe:swipeMode="both" />
  • swipeFrontView - Required - front view id.
  • swipeBackView - Required - back view id.
  • swipeActionLeft - Optional - left swipe action Default: 'reveal'
  • swipeActionRight - Optional - right swipe action Default: 'reveal'
  • swipeMode - Gestures to enable or 'none'. Default: 'both'
  • swipeCloseAllItemsWhenMoveList - Close revealed items on list motion. Default: 'true'
  • swipeOpenOnLongPress - Reveal on long press Default: 'true'
  • swipeAnimationTime - item drop animation time. Default: android configuration
  • swipeOffsetLeft - left offset
  • swipeOffsetRight - right offset
In java :
private PullToRefreshSwipeListView ptrList;
private SwipeListView swipeList;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_list);
ptrList = (PullToRefreshSwipeListView)findViewById(R.id.sphr_listview);
swipeList = ptrList.getRefreshableView();      
ptrList.setOnRefreshListener(new OnRefreshListener2<SwipeListView>() {
           @Override
           public void onPullDownToRefresh(PullToRefreshBase<SwipeListView> refreshView){
               // TODO Auto-generated method stub

           }

           @Override
           public void onPullUpToRefresh(PullToRefreshBase<SwipeListView> refreshView) {
               // TODO Auto-generated method stub

           }

       });
}

set adapter in list-view as shown below.
  private void setListData() {
   adapter = new DataAdapter(this, R.layout.item_library_list, new ArrayList<PurchasedItem>(), resultListView);
    
    swipeList.setSwipeListViewListener(new BaseSwipeListViewListener() {   
     @Override
        public void onClickFrontView(final int position) {
            //do something here on Frontview click
        } 
       @Override
        public void onClickBackView(final int position) {
            //do something here on Backview click
        } 

      @Override
        public void onOpened(int position, boolean toRight) {
            // TODO Auto-generated method stub
            super.onOpened(position-1, toRight);
            lastPos = position-1;
        }

        @Override
        public void onMove(int position, float x) {
            // TODO Auto-generated method stub
            super.onMove(position-1, x);
        }

        @Override
        public int onChangeSwipeMode(int position) {
            // TODO Auto-generated method stub
                        return SwipeListView.SWIPE_MODE_DEFAULT;
        }

        @Override
        public void onStartOpen(int position, int action, boolean right) {
            // TODO Auto-generated method stub
            super.onStartOpen(position-1, action, right);

        }

    });

    ptrList.setAdapter(adapter); 
    ptrList.setLongClickable(true); 
    swipeList.setSwipeOpenOnLongPress(false);  
    }

Friday, 18 October 2013

Quick pop-up with animation like Google Chrome .

Quick pop-up same as Google Chrome which appear when you first time start Chrome.
Here in this pop-up use animation which will be used to create a floating fill to pop-up.

How to use ?
QuickPopup quickPopup = new QuickPopup(MainActivity.this, "Hi :)");
quickPopup.show(view);

QuickPopup.java

public class QuickPopup {

protected WindowManager mWindowManager;
protected Context mContext;
protected Drawable mBackgroundDrawable = null;
protected PopupWindow mWindow;
private TextView txtShow;
private ImageView imgUp, imgDown;
protected View mView;
protected ShowPopUpListener showpopupListener;

public QuickPopup(Context context, String text, int viewResource) {
mContext = context;
mWindow = new PopupWindow(context);
mWindowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
initCompo(viewResource);
}

public QuickPopup(Context context) {
this(context, "", R.layout.popup);
}

public QuickPopup(Context context, String text) {
this(context);
setText(text);
}

private void initCompo(int viewResource) {
LayoutInflater layoutInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

setContentView(layoutInflater.inflate(viewResource, null));

txtShow = (TextView) mView.findViewById(R.id.text);
imgUp = (ImageView) mView.findViewById(R.id.arrow_up);
imgDown = (ImageView) mView.findViewById(R.id.arrow_down);

txtShow.setMovementMethod(ScrollingMovementMethod.getInstance());
txtShow.setSelected(true);
}

public void show(View anchor) {
preShow();

int[] location = new int[2];

anchor.getLocationOnScreen(location);

Rect anchorRect = new Rect(location[0], location[1], location[0]
+ anchor.getWidth(), location[1] + anchor.getHeight());

mView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

int rootHeight = mView.getMeasuredHeight();
int rootWidth = mView.getMeasuredWidth();

final int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
final int screenHeight = mWindowManager.getDefaultDisplay().getHeight();

int yPos = anchorRect.top - rootHeight;

boolean onTop = true;

if (anchorRect.top < screenHeight / 2) {
yPos = anchorRect.bottom;
onTop = false;
}

int whichArrow, requestedX;

whichArrow = ((onTop) ? R.id.arrow_down : R.id.arrow_up);
requestedX = anchorRect.centerX();

View arrow = whichArrow == R.id.arrow_up ? imgUp : imgDown;
View hideArrow = whichArrow == R.id.arrow_up ? imgDown : imgUp;

final int arrowWidth = arrow.getMeasuredWidth();

arrow.setVisibility(View.VISIBLE);

ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams) arrow
.getLayoutParams();

hideArrow.setVisibility(View.INVISIBLE);

int xPos = 0;

if (anchorRect.left + rootWidth > screenWidth) {
xPos = (screenWidth - rootWidth);// right click
} else if (anchorRect.left - (rootWidth / 2) < 0) {
xPos = anchorRect.left;// left clcik
} else {
xPos = (anchorRect.centerX() - (rootWidth / 2)); // inbetween
}

param.leftMargin = (requestedX - xPos) - (arrowWidth / 2);

if (onTop) {
txtShow.setMaxHeight(anchorRect.top - anchorRect.height());

} else {
txtShow.setMaxHeight(screenHeight - yPos);
}

mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);

mView.setAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.float_anim));

}

protected void preShow() {
if (mView == null)
throw new IllegalStateException("view undefined");

if (showpopupListener != null) {
showpopupListener.onPreShow();
showpopupListener.onShow();
}

if (mBackgroundDrawable == null)
mWindow.setBackgroundDrawable(new BitmapDrawable());
else
mWindow.setBackgroundDrawable(mBackgroundDrawable);

mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
mWindow.setTouchable(true);
mWindow.setFocusable(true);
mWindow.setOutsideTouchable(true);

mWindow.setContentView(mView);
}

public void setBackgroundDrawable(Drawable background) {
mBackgroundDrawable = background;
}

public void setContentView(View root) {
mView = root;

mWindow.setContentView(root);
}

public void setContentView(int layoutResID) {
LayoutInflater inflator = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

setContentView(inflator.inflate(layoutResID, null));
}

public void setOnDismissListener(PopupWindow.OnDismissListener listener) {
mWindow.setOnDismissListener(listener);
}

public void dismiss() {
mWindow.dismiss();
if (showpopupListener != null) {
showpopupListener.onDismiss();
}
}

public void setText(String text) {
txtShow.setText(text);
}

public void setShowListener(ShowPopUpListener showpopupListener) {
this.showpopupListener = showpopupListener;
}
}


Interface

public interface ShowPopUpListener {
void onPreShow();

void onDismiss();

void onShow();
}

res/anim/float_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:interpolator="@android:anim/bounce_interpolator"
        android:duration="1000"
        android:fillAfter="true"
        android:fromYDelta="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:repeatMode="reverse"
        android:toYDelta="5%" />

</set>



Wednesday, 25 September 2013

Video Recording in Background Using service Android

Here ,There is one Sample activity which records video in background using of service.

MainVideoActivity.class


public class MainVideoActivity extends Activity implements
SurfaceHolder.Callback {

public static SurfaceView mSurfaceView;
public static SurfaceHolder mSurfaceHolder;
public static Camera mCamera;
public static boolean mPreviewRunning;

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_video);

mSurfaceView = (SurfaceView) findViewById(R.id.surfaceview);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

Button startVideoButton = (Button) findViewById(R.id.button1);
startVideoButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
startService(new Intent(MainVideoActivity.this,
RecorderService.class));
}
});

Button stopVideoButton = (Button) findViewById(R.id.button2);
stopVideoButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
stopService(new Intent(MainVideoActivity.this,
RecorderService.class));
}
});
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}


RecorderService.class (For start and stop  video recording )

public class RecorderService extends Service {
private SurfaceHolder mSurfaceHolder;
private static Camera camera;
public static boolean recordingStatus;
private MediaRecorder mediaRecorder;
private File directory;
private int cameraType = 0;

@Override
public void onCreate() {
recordingStatus = false;
camera = MainVideoActivity.mCamera;
mSurfaceHolder = MainVideoActivity.mSurfaceHolder;

super.onCreate();
}

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
if (recordingStatus == false) {

startRecording();
}

return START_STICKY;
}

@Override
public void onDestroy() {
stopRecording();
camera.release();
recordingStatus = false;

super.onDestroy();
}

@SuppressLint("NewApi")
public boolean startRecording() {
try {
recordingStatus = true;

camera = Camera.open(cameraType);
camera.setDisplayOrientation(90);
Camera.Parameters params = camera.getParameters();
camera.setParameters(params);
Camera.Parameters p = camera.getParameters();

camera.setParameters(p);

camera.unlock();

mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

directory = new File(Environment.getExternalStorageDirectory()
.toString() + "/videodemo/");
if (!directory.exists())
directory.mkdirs();

long currentTime = System.currentTimeMillis();

String uniqueOutFile = Environment.getExternalStorageDirectory()
.toString()
+ "/videodemo/videooutput"
+ currentTime
+ ".mp4";
File outFile = new File(directory, uniqueOutFile);
if (outFile.exists()) {
outFile.delete();
}

mediaRecorder.setOutputFile(uniqueOutFile);

mediaRecorder.setVideoSize(350, 250);
mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mediaRecorder.setOrientationHint(90);

mediaRecorder.prepare();
mediaRecorder.start();

return true;
} catch (IllegalStateException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}

// Stop service
public void stopRecording() {
mediaRecorder.stop();
mediaRecorder.release();
}
}

Add below permission in manifest file.

<uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

define service.
 <service android:name="com.videodemo.RecorderService" />

Copy and share your useful data from Google chrome browser to your application in android.

Here In this blog I explain that how to copy and share your useful data from chrome browser in android. 1) How to show your applic...