Tuesday, 25 November 2014

Custom Popup Menu

Custom Popup Menu

Simple example for custom popup menu:




public class MainActivity extends Activity 
{
Button btnOpenPopup;
PopupWindow popupWindow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnOpenPopup = (Button) findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener() 
{
@SuppressLint("InflateParams") @Override
public void onClick(View arg0) 
{
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_window_custom, null);
popupWindow = new PopupWindow(popupView,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new ColorDrawable());/*(this is important)Must Use*/
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
// popupWindow.showAtLocation(btnOpenPopup, Gravity.NO_GRAVITY, 0, 0);/*No use with this*/
// popupWindow.showAsDropDown(btnOpenPopup);
popupWindow.showAsDropDown(btnOpenPopup,btnOpenPopup.getWidth() / 2, 0);
}
});
}
}

Click this Link to Download Source Code Click here

Making Round Corner Background in Android using xml
Create one new XML like bg_corner.xml & Put this xml as Background for any View
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:topLeftRadius="0dp"
      android:topRightRadius="30dp"
      android:bottomRightRadius="30dp"
      android:bottomLeftRadius="30dp" />
  <stroke
      android:width="3dp"
      android:color="#000000" />
  <solid
      android:color="#800000c0"/>
</shape>
(This will make Background Image like this)


(OR)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="30dp" />
  <stroke
      android:width="3dp"
      android:color="#000000" />
  <solid
      android:color="#800000c0"/>
</shape>
(This will make Background Image like this)

Tuesday, 10 June 2014

GETTING GOOGLE MAP API KEY FOR SIGNED APP


If you are using MAP KEY in Signed Application means you have to keep two things in your mind:
(If you are using Normally Generated Map key means it will not show the MAP)

1.Before Creating the API Key you have to sign Your APP

2. After that you have to give your signed keystore file  and alias name in cmd

(a) You Have to do like below in CMD

C:\Program Files\Java\jdk1.6.0_18\bin>keytool -list -v -keystore "(keystore file path)" -alias (what the alias name you have given while signing the app)

Enter keystore password:
Alias name: zingmobile
Creation date: Jun 10, 2014
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=zingmobile
Issuer: CN=zingmobile
Serial number: 5396b2e8
Valid from: Tue Jun 10 12:55:28 IST 2014 until: Mon Oct 11 12:55:28 IST 3013
Certificate fingerprints:
         MD5:  A9:C7:34:09:FE:64:44:2D:43:A7:0C:A3:58:77:07:33
         SHA1: 7B:EF:27:02:84:1F:6B:2E:54:D2:C1:F8:CF:D0:42:C2:36:F0:53:E1
         Signature algorithm name: SHA1withRSA
         Version: 3
C:\Program Files\Java\jdk1.6.0_18\bin>

(b) After that go to below link and click Create New Project

                https://console.developers.google.com/project

GETTING GOOGLE MAP API KEY

(a) First you need to get SHA1 Using CMD

C:\Program Files\Java\jdk1.6.0_18\bin>keytool -list -v -keystore "C:\Users\VENGAT\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Alias name: androiddebugkey
Creation date: May 18, 2013
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 519685a5
Valid from: Sat May 18 01:01:49 IST 2013 until: Mon May 11 01:01:49 IST 2043
Certificate fingerprints:
         MD5:  3C:DA:8B:E1:BA:44:41:1B:70:0B:87:78:99:69:CD:A1
         SHA1: F7:02:FE:B4:3D:3D:59:9D:33:83:E4:93:C9:CC:AF:C9:22:12:88:E1
         Signature algorithm name: SHA1withRSA
         Version: 3
C:\Program Files\Java\jdk1.6.0_18\bin>

(b) Second go to below link and click Create New Project

Wednesday, 4 June 2014

Finishing One Activity From Another Activity

First_Activity :

Create Activity Object in First_Activity..

--> static Activity closing = this;




Second_Activity:

Close the First_Activity in Second_Activity Using Activity Object..
--> First_Activity.closing.finish();



Wednesday, 7 May 2014

Moving a File From One Directory To Another Directory In Android Programmatically (SIMPLE)

SourceFilePath is the current  path of which file you are going to move

DestinationFilePath is the path where you are going to move that file

File SourceFile = new File(SourceFilePath);
   
File DestinationFile = new File(DestinationFilePath);
        
if(SourceFile.renameTo(DestinationFile))    
{
      Log.v("Moving", "Moving file successful."); 
}
else
{
      Log.v("Moving", "Moving file failed.");
}

Moving a File From One Directory To Another Directory In Android Programmatically

private void moveFile(String inputPath, String inputFile, String outputPath) 
{
    InputStream in = null;
    OutputStream out = null;
    try 
    {
        //create output directory if it doesn't exist
        File dir = new File (outputPath); 
        if (!dir.exists())
        {
            dir.mkdirs();
        }

        in = new FileInputStream(inputPath + inputFile);        
        out = new FileOutputStream(outputPath + inputFile);

        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
        }
        in.close();
        in = null;

        // write the output file
        out.flush();
        out.close();
        out = null;

        // delete the original file
        new File(inputPath + inputFile).delete();  
    } 
    catch (FileNotFoundException fnfe1) {
    Log.e("tag", fnfe1.getMessage());
    }
    catch (Exception e) {
    Log.e("tag", e.getMessage());
    }
}