flipkart

Friday, November 7, 2014

Navigation Drawer in Android

Navigation Drawer is list of layout but it most time always hidden when user swipe left edge side to right it will come and when user will touch it will hidden based on user selecting it will open information.

Now i will explain Navigation Drawer with example one by one file i will explain

activity_main.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ListView android:id="@+id/listview1"
        android:layout_width="140dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:background="#244848"/>
</android.support.v4.widget.DrawerLayout>

ListView will show name of the pages and FrameLayout is information of selected one nothing but fragment.

fragment1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:gravity="center"
    android:background="#488844"

    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40px"
        android:textColor="#ffffff"
        android:layout_gravity="center"
        android:id="@+id/textview1"/>
</LinearLayout>

When ever select one it will open new fragment that fragment consists currently only one textview .

MainActivity.java

package com.vamsi.navidrawer;

import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
       String[] menu;
       DrawerLayout dLayout;
       ListView dList;
       ArrayAdapter<String> adapter;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
        menu = new String[]{"BALL","BAT","CUP","CRICKET","WICKET","GROUND","OUT","WIN"};
          dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
          dList = (ListView) findViewById(R.id.listview1);
          adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menu);
          dList.setAdapter(adapter);
      dList.setSelector(android.R.color.darker_gray);
          dList.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
          dLayout.closeDrawers();
          Bundle args = new Bundle();
          args.putString("details", menu[position]);
          Fragment detail = new Fragment1();
          detail.setArguments(args);
            FragmentManager fragmentManager = getFragmentManager();
          fragmentManager.beginTransaction().replace(R.id.framelayout, detail).commit();
        }
          });
  }

}

This is my mainactivity of project this having initialization of elements and other stuff

Fragment1.java 

package com.vamsi.navidrawer;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class Fragment1 extends Fragment {
    TextView text;
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle args) {
        View view = inflater.inflate(R.layout.fragment1, container, false);
        String menu = getArguments().getString("details");
        text= (TextView) view.findViewById(R.id.textview1);
        text.setText(menu);
        return view;
    }

}

This class is user when ever user click it open this fragment 

following screen-shots above project 


                When ever user swipe left to right following screen will come


                                      when ever user select based it show following fragment





Thank you studying my post please put comments it will be very use full for me 

Saturday, November 1, 2014

Mobile Detecting problem using adb

After installation of android SDK open terminal go to directory of your platform-tools using cd command on terminal after connect your android mobile to system through USB cable before connecting check debug is enable or not in your phone, how check enable or not go to setting on your phone developer options tick debug option if disable. Following command type for detecting  your mobile into your system

$adb devices 

Normally it will your phone some situations it will not detect, type following commands

$adb kill-server

it will kill server of adb

$adb start-server

$adb devices 

Now almost it will detect still it not detect do following steps

$cd /etc/udev/rules.d/

$sudo vi 51-android.rules

After opening vi editor goto last line of script type following line

SUBSYSTEM="usb",ATTR{idVendor}=="vendor id", MODE="0666"

for finding vendor of mobile type lsusb command after typing above line save and quit (:wq)
http://developer.android.com/tools/device.html

$sudo chmod a+rx /etc/udev/rules.d/51-android.rules 

$service udev restart 

$adb kill-server

Now try,

$adb start-server

$adb devices 

Hopefully it will detect still it not detect follow following procedure
First  open new  terminal

$cd  ~/.android/

$vi adb_usb.ini

there write vendor id of your phone next save file

$adb kill-server

$adb start-server

$adb devices




Now it detected successfully for me try your self 


Running python server current directory in Ubuntu

Today i am going to explain running python server in Ubuntu it is  for temporally purpose suppose normally for running server we need install some software like Apache or tomcat etc. But no need to install extra software and no much space extra in memory only one command is enough for running server for current directory.
   
         After opening terminal (Ctrl+Alt+terminal) once check python installed or not i think all most every Ubuntu python is inbuilt package so no need wary about installation of python if python is not there simply type following on your  terminal

$ sudo apt-get install python
                 
              or 
open synaptic manager search python package after install 


After successful installation of python open terminal type following command
before running command which you want run server go that directory cd command

$ python -m SimpleHTTPServer

After typing above command it will run python server on your host system if want cross check server is running or not  open any browser type following line tab.

http://localhost:8000/

Normally it will take default port number is 8000 if want change you can  on terminal following command

$python -m SimpleHTTPServer 8088

Now port number changed as your wish


Convert Rectangle (Square) images to Circle using GIMP tool

Today i faced one problem i download one image from google but that image shape is rectangle , i want circle after download image lot of online tools is there for converting one shape to another shape but it not safe why means they will save our images into their data base in this situation i like to explain my real experience in online.

After completion my graduation i prepared my resume through open office after preparing resume i will carry resume through pen-drive but where ever i open it showing little bit modifying original one i decided to convert pdf . I done through online .doc to .pdf conversion now my problem is solved.
After some day gone i am searching some suddenly i socked because my resume is opened that i understood they our contents into their data bases so take care .

now will move this post main aim " conversion rectangle image to circle image " today i found out some offline tool GIMP

I will explain step by step procedure with help of some images

My image name image.jpg



Step 1:First select image and right click om image next select open with ->GIMP Image Editor 


Step2: now it GIMP tool is opened now select which shape you want (ex: circle) goto Tools->Select Tools->Ellipse select

 

Step3: After selecting shape click Layer->Mask->Add Layer Mask->Selection



Note: select size of circle according to your customize 

Now press once Enter button in keyboard  save image .xcf extension 

Step 4:For saving image and customize format click File->export and save image as your wish 



Now our rectangle image converted to circle image with safety.




Friday, October 31, 2014

Changing IP address of SVN Host (Server)

Daily i am using SVN for code submitting to my superiors  but one day unfortunately i am try to submit code to SVN but it showing some error after some i identified my SVN system IP address is changed .
I don't know to change IP old to new IP address for that solution is following command line we can change IP address of SVN


$svn switch  relocate http://old_ip_address/svn/project_name http://new_ip_address/svn/project_name



above command working in Ubuntu terminal 

For Solving two equation through online

In our daily life we busy with developing new application and writing new code but unfortunately some times we need to solve some equations solving equations is some what tricky

examples:

solving two straight line equations is very easy process but solving two ellipses equation little tricky process so for that some online website is there . This website we have to enter two equation they will give intersection between two equation

link is http://www.wolframalpha.com/

Tuesday, July 15, 2014

JSON parsing in Android application

Today i will explain how to parse JSON (Java Script Object Notation) in android application.
Following file my source code

MainActivity.java
  1. package com.example.jsonparcer;

    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import org.json.JSONObject;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;

    public class MainActivity extends Activity {

        BufferedReader bReader = null;
        TextView name,date,hours;
        Button data;
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    name=(TextView) findViewById(R.id.name);
    date=(TextView) findViewById(R.id.date);
    hours=(TextView) findViewById(R.id.hours);
    data=(Button) findViewById(R.id.data);
    data.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    try {


    InputStream work = getApplicationContext().getResources()
                   .openRawResource(R.raw.work);

    bReader=new BufferedReader(new InputStreamReader(work));
    StringBuilder quesString = new StringBuilder();
            String aJsonLine = null;
            while ((aJsonLine = bReader.readLine()) != null) {
                    quesString.append(aJsonLine);
            }
           
            Log.d(this.getClass().toString(), quesString.toString());
            String workjson=quesString.toString();
            JSONObject quesObj = new JSONObject(quesString.toString());
            JSONObject TimeTable  = quesObj.getJSONObject("TimeTable");
            name.append(TimeTable.getString("name"));
            date.append(TimeTable.getString("date"));
            hours.append(TimeTable.getString("time"));
           
    } catch (Exception e){
             
           } finally {
                       try {
                               bReader.close();
                       } catch (Exception e) {
                               Log.e("", e.getMessage().toString(), e.getCause());
                       }

           }

    }
    });



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

    }
AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.jsonparcer"
  android:versionCode="1"
  android:versionName="1.0" >

  <uses-sdk
  android:minSdkVersion="8"
  android:targetSdkVersion="19" />

  <application
  android:allowBackup="true"
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name"
  android:theme="@style/AppTheme" >
  <activity
  android:name="com.example.jsonparcer.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>

</manifest>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" >

  <TextView
  android:id="@+id/name"
  android:layout_width="wrap_content"
  android:textSize="20dp"
  android:layout_height="wrap_content"
  android:text="@string/Employ" />

  <TextView
  android:id="@+id/date"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="20dp"
  android:layout_alignLeft="@+id/name"
  android:layout_below="@+id/name"
  android:layout_marginTop="23dp"
  android:text="@string/Date" />

  <TextView
  android:id="@+id/hours"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="20dp"
  android:layout_below="@+id/date"
  android:layout_marginTop="26dp"
  android:text="@string/Time" />

  <Button
  android:id="@+id/data"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:layout_centerHorizontal="true"
  android:layout_marginBottom="126dp"
  android:text="@string/Data" />

</RelativeLayout>


strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <string name="app_name">Jsonparcer</string>
  <string name="action_settings">Settings</string>
  <string name="hello_world">Hello world!</string>
  <string name="Employ">Ename :</string>
  <string name="Date">Date :</string>
  <string name="Time">WHours :</string>
  <string name="Data">Data</string>

</resources>

work.txt

{
  "TimeTable":{
  "name":"Vamsi",
  "date":"8-07-2014",
  "time":"8hours"
  }
}

Above codes are my source code for parsing json object using android . After running above code following screenshot will be generated


After button pressing it will retrieve data from work.txt next it will show using Textview on screen




Monday, July 7, 2014

Creating JSON file programitically

JSON stands for Java Script Object Notation. It is user for data saving .Today this post explain creating JSON file and writing values inside file using android programming.


MainActivity.java


 package com.example.jsonwriter;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
JSONObject object = new JSONObject();
 try {
   object.put("name", "vamsi krishna");
   object.put("score", new Integer(44));
   object.put("current", new Double(40));
   object.put("nickname", "vk");
 } catch (JSONException e) {
   e.printStackTrace();
 }
 System.out.println("------"+object);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

AndroidManifest.xml, layout file are same after creating project change accordingly as your date in MainActivity class  

After running above my application it will give following screenshots


Above picture logcat showing out of application(Green color lines)


Tuesday, May 20, 2014

JNI Development using eclipse

Hi, every body knows programming of C language so they write already code in C language. This post i will try explain how to use C function in Java using eclipse.Following explain is based on Ubuntu operating system


First create java project 


File -> New -> Java Project

After created java project add java source file

right click on src folder select New->class

Write java source code file and save it

Right click on project folder select new -> folder

Give folder name as jni after press finish

Once press build project

Right click on project press Build project

Next go Run -> External tool configurations 

It's opened one window select program next click new 

Location field is javah exceutable file path

working directory is present project bin folder

Arguments is "-jni -classpath ${workspace_loc:/Hello/bin} -d ${workspace_loc:/Hello/jni} Hello " 

it's created java header file inside jni folder use that file for creation c source file before that one move C/C++ perspective

Right click on project New -> Other -> Convert to a C/C++ Project 

After selecting press Next inside select C project or C++ project after Shared library next press finish button

Before writing C source code right click project select Build Path -> Configure Build Path after it opend window inside window 

C/C++ Build -> Settings ->Includes -> select New after give path /usr/lib/jvm/java-6-openjdk/include

Next press OK button and Create New C source file using java Header file

After Build C/C++ perspective next return Java perspective

Once Build project

Right click project Run as -> Run Configurations 

Select inside Java Application -> project name -> Arguments -> 

Field VM arguments -Djava.library.path=$UR_PATH/project_name/Debug/