Tuesday, 29 September 2015

QR Code Generation From Text using Zxing Library

package com.example.qrstring;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

import android.graphics.Bitmap;


import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;

public class MainActivity extends ActionBarActivity {
   
    public final static int WHITE = 0xFFFFFFFF;
    public final static int BLACK = 0xFF000000;
    public final static int WIDTH = 400;
    public final static int HEIGHT = 400;
    public final static String STR = "Abhishek";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView imageView = (ImageView) findViewById(R.id.qr);
        try {
            Bitmap bitmap = encodeAsBitmap(STR);
            imageView.setImageBitmap(bitmap);
        } catch (WriterException e) {
            e.printStackTrace();
        }
    }

    Bitmap encodeAsBitmap(String str) throws WriterException {
        BitMatrix result;
        try {
            result = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, null);
        } catch (IllegalArgumentException iae) {
            // Unsupported format
            return null;
        }
       
        int width = result.getWidth();
        int height = result.getHeight();
        int[] pixels = new int[width * height];
        for (int y = 0; y < height; y++) {
            int offset = y * width;
            for (int x = 0; x < width; x++) {
                pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
            }
        }
       
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        return bitmap;
    }

    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Tuesday, 1 September 2015

KESCO APP SNAPSHOT OF TRANSFORMER DETAILS And Register Activity XML


                                         


                                                 REGISTER ACTIVITY




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_register"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp" >

        <EditText
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@color/input_register_bg"
            android:hint="@string/hint_name"
            android:padding="10dp"
            android:singleLine="true"
            android:inputType="textCapWords"
            android:textColor="@color/input_register"
            android:textColorHint="@color/input_register_hint" />

        <EditText
            android:id="@+id/email"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@color/input_register_bg"
            android:hint="@string/hint_email"
            android:inputType="textEmailAddress"
            android:padding="10dp"
            android:singleLine="true"
            android:textColor="@color/input_register"
            android:textColorHint="@color/input_register_hint" />

        <EditText
            android:id="@+id/password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@color/input_register_bg"
            android:hint="@string/hint_password"
            android:inputType="textPassword"
            android:padding="10dp"
            android:singleLine="true"
            android:textColor="@color/input_register"
            android:textColorHint="@color/input_register_hint" />

        <!-- Login Button -->

        <Button
            android:id="@+id/btnRegister"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:background="#ea4c88"
            android:text="@string/btn_register"
            android:textColor="@color/white" />

        <!-- Link to Login Screen -->

        <Button
            android:id="@+id/btnLinkToLoginScreen"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dip"
            android:background="@null"
            android:text="@string/btn_link_to_login"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="15dp" />
    </LinearLayout>

</LinearLayout>

Monday, 31 August 2015

KESCO APP







LOGIN LAYOUT

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_login"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp" >

        <EditText
            android:id="@+id/email"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@color/white"
            android:hint="@string/hint_email"
            android:inputType="textEmailAddress"
            android:padding="10dp"
            android:singleLine="true"
            android:textColor="@color/input_login"
            android:textColorHint="@color/input_login_hint" />

        <EditText
            android:id="@+id/password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@color/white"
            android:hint="@string/hint_password"
            android:inputType="textPassword"
            android:padding="10dp"
            android:singleLine="true"
            android:textColor="@color/input_login"
            android:textColorHint="@color/input_login_hint" />

        <!-- Login Button -->

        <Button
            android:id="@+id/btnLogin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:background="@color/btn_login_bg"
            android:text="@string/btn_login"
            android:textColor="@color/btn_login" />

        <!-- Link to Login Screen -->

        <Button
            android:id="@+id/btnLinkToRegisterScreen"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dip"
            android:background="@null"
            android:text="@string/btn_link_to_register"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="15dp" />
    </LinearLayout>

</LinearLayout>

Saturday, 22 August 2015

Android Image capture

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera);
        Button txt1=(Button)findViewById(R.id.dissum);
        Button txt2=(Button)findViewById(R.id.dup);
        txt1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                   
                //Toast.makeText(getApplicationContext(), "Under construction....  " , Toast.LENGTH_LONG).show();

                   
 //                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//                     File f = new File(android.os.Environment.getExternalStorageDirectory(), "subtemp.jpg");
//                     intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
//                     startActivityForResult(intent, 1);
                   
                    String fileName = "subimage.jpg";
                       //create parameters for Intent with filename
                       ContentValues values = new ContentValues();
                       values.put(MediaStore.Images.Media.TITLE, fileName);
                       values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
                       //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
                       imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                       //create new Intent
                       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                       intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                       intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                       startActivityForResult(intent, 1);
                }
               
               
            });
        txt2.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                   
                    gps = new GPSTracker(camera.this);
                   
                    // check if GPS enabled   
                    if(gps.canGetLocation()){
                        
                        latitude = gps.getLatitude();
                       longitude = gps.getLongitude();
                         if(latitude!=0 && longitude!=0)
                         {
                             if (bitmap == null) {
                                 Toast.makeText(getApplicationContext(),
                                         "Please Select Image ..", Toast.LENGTH_SHORT).show();
                             } else {
//                                 dialog = ProgressDialog.show(SellMyProperty.this, "Uploading",
//                                         "Please wait...", true);
                            
                         new ImageUploadTask().execute();
                             }
                         }
                         else{
                                Toast.makeText(getApplicationContext(), "Please Wait Gps fetch the value....  " , Toast.LENGTH_LONG).show();
                            }
                        // \n is for new line
                       Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();  
                   //latlong="Lat:-"+latitude+"Long:-"+longitude+" ";
                  
                   
                   
                 
                    }else{
                        // can't get location
                        // GPS or Network is not enabled
                        // Ask user to enable GPS/network in settings
                         buildAlertMessageNoGps();
                      
                     //  Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();  
                       // latlong="Lat:-"+latitude+"Long:-"+longitude+" ";
                       
                    }
                   
               
                }
                });
       
    }

   

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
       
        String filePath = null;
        if (resultCode == RESULT_OK) {
            if (requestCode == 1) {

                 selectedImageUri = imageUri;
            } else if (requestCode == 2) {
               
                selectedImageUri = data.getData();
//                Uri selectedImageUri = data.getData();
//                String p=selectedImageUri.getPath();
//
//                String tempPath = data.getDataString();
//                Log.i("path of image from gallery......******************.........", p);
//                Bitmap bitmap;
//                BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
//                bitmap = BitmapFactory.decodeFile(tempPath, bitmapOptions);
//                imgView.setImageBitmap(bitmap);

//                Uri selectedImage = data.getData();
//                String[] filePath = { MediaStore.Images.Media.DATA };
//                Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);
//                c.moveToFirst();
//                int columnIndex = c.getColumnIndex(filePath[0]);
//                String picturePath = c.getString(columnIndex);
//                c.close();
//                Bitmap bitmap = (BitmapFactory.decodeFile(picturePath));
//                Log.w("path of image from gallery......******************.........", picturePath+"");
//                imgView.setImageBitmap(bitmap);
            }
           
            if(selectedImageUri != null){
             try {
                 // OI FILE Manager
                 String filemanagerstring = selectedImageUri.getPath();

                 // MEDIA GALLERY
                 String selectedImagePath = getPath(selectedImageUri);
//                 txt9.setText(selectedImagePath);
                 if (selectedImagePath != null) {
                     filePath = selectedImagePath;
                 } else if (filemanagerstring != null) {
                     filePath = filemanagerstring;
                 } else {
                     Toast.makeText(getApplicationContext(), "Unknown path",
                             Toast.LENGTH_LONG).show();
                     Log.e("Bitmap", "Unknown path");
                 }

                 if (filePath != null) {
                     decodeFile(filePath);
                 } else {
                     bitmap = null;
                 }
             } catch (Exception e) {
                 Toast.makeText(getApplicationContext(), "Internal error",
                         Toast.LENGTH_LONG).show();
                 Log.e(e.getClass().getName(), e.getMessage(), e);
             }
     }
        }



}