Thursday 12 March 2015

Contacts we have

package com.cssoft.speedlocker;

import com.cssoft.fonts.MyFonts;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ContactsTab extends Activity {

private EditText edit_search;
private Button btn_all, btn_supervisor, btn_monitored;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts_tab);

getUI();
setFonts();
}

private void getUI() {
edit_search = (EditText) findViewById(R.id.edit_contact_search);
btn_all = (Button) findViewById(R.id.btn_contact_all);
btn_supervisor = (Button) findViewById(R.id.btn_contact_supervisor);
btn_monitored = (Button) findViewById(R.id.btn_contact_monitored);

}

private void setFonts() {
edit_search.setTypeface(MyFonts.RobotoMedium(this));
btn_all.setTypeface(MyFonts.RobotoMedium(this));
btn_supervisor.setTypeface(MyFonts.RobotoMedium(this));
btn_monitored.setTypeface(MyFonts.RobotoMedium(this));
}
}

Monday 9 March 2015

GCM Intent Service

package com.cssoft.speedlocker;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import static com.cssoft.speedlocker.CommonUtilities.SENDER_ID;

import com.cssoft.speedlocker.R;
import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {

    private static final String TAG = "GCMIntentService";

    public GCMIntentService() {
        super(SENDER_ID);
    }

    /**
     * Method called on d evice registered
     **/
    @Override
    protected void onRegistered(Context context, String registrationId) {
        Log.i(TAG, "Device registered: regId = " + registrationId);
     
    }

    /**
     * Method called on device un registred
     * */
    @Override
    protected void onUnregistered(Context context, String registrationId) {
        Log.i(TAG, "Device unregistered");
     
    }

    /**
     * Method called on Receiving a new message
     * */
    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
     
     
    }

    /**
     * Method called on receiving a deleted message
     * */
    @Override
    protected void onDeletedMessages(Context context, int total) {
        Log.i(TAG, "Received deleted messages notification");
     
   
    }

    /**
     * Method called on Error
     * */
    @Override
    public void onError(Context context, String errorId) {
        Log.i(TAG, "Received error: " + errorId);
     
    }

    @Override
    protected boolean onRecoverableError(Context context, String errorId) {
        // log message
        Log.i(TAG, "Received recoverable error: " + errorId);
     
        return super.onRecoverableError(context, errorId);
    }

    /**
     * Issues a notification to inform the user that server has sent a message.
     */
    private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_launcher;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
       
        String title = context.getString(R.string.app_name);
       
        Intent notificationIntent = new Intent(context, SplashActivity.class);
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
       
        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;
       
        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);    

    }

}

Thursday 5 March 2015

forget password activity

package com.cssoft.speedlocker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.cssoft.fonts.MyFonts;
import com.cssoft.validation.Validations;
import com.cssoft.webservices.ForgotPassword;

public class ForgotActivity extends Activity {

private TextView txt_text;
private EditText edit_email;
private Button btn_send;
private Validations valid;

@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgot);

valid = new Validations(ForgotActivity.this);

getUI();
setFonts();
clickEvents();
}

private void getUI() {
txt_text = (TextView) findViewById(R.id.txt_forgot_text);
edit_email = (EditText) findViewById(R.id.edit_forgot_email);
btn_send = (Button) findViewById(R.id.btn_forgot_send);
}

private void setFonts() {
txt_text.setTypeface(MyFonts.RobotoMedium(this));
edit_email.setTypeface(MyFonts.RobotoMedium(this));
btn_send.setTypeface(MyFonts.RobotoMedium(this));
}

private void clickEvents() {
btn_send.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String email = edit_email.getText().toString().trim();

if (!valid.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter Email ID",
Toast.LENGTH_SHORT).show();
} else if (!valid.isValidEmail(email)) {
Toast.makeText(getApplicationContext(),
"Enter Valid Email ID", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "OK",
Toast.LENGTH_SHORT).show();

new ForgotPassword(ForgotActivity.this).execute(email);
}

}
});
}
}

Tuesday 3 March 2015

splash activity

package com.cssoft.speedlocker;

import static com.cssoft.speedlocker.CommonUtilities.DISPLAY_MESSAGE_ACTION;
import static com.cssoft.speedlocker.CommonUtilities.EXTRA_MESSAGE;
import static com.cssoft.speedlocker.CommonUtilities.SENDER_ID;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.cssoft.fonts.MyFonts;
import com.cssoft.sharedpref.GetSharedPref;
import com.cssoft.sharedpref.SetSharedPref;
import com.cssoft.speedlocker.R;
import com.google.android.gcm.GCMRegistrar;

public class SplashActivity extends Activity {

AsyncTask<Void, Void, Void> mRegisterTask;
private TextView txt_loading;

@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

registerDevice();

/*
* new Handler().postDelayed(new Runnable() {
*
* @Override public void run() { registerDevice();
*
* } }, 5000);
*/

getUI();
startIntent();
}

private void getUI() {
txt_loading = (TextView) findViewById(R.id.loading);
txt_loading.setTypeface(MyFonts.AirStrike(this));
}

int count = 1;

private void startIntent() {

new Timer().scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {

runOnUiThread(new Runnable() {
public void run() {
if (count == 1) {
txt_loading.setText("Loading.");
count = 2;
} else if (count == 2) {
txt_loading.setText("Loading..");
count = 3;
} else if (count == 3) {
txt_loading.setText("Loading...");
cancel();
}
}
});

}
}, 0, 1000);

new Handler().postDelayed(new Runnable() {

@Override
public void run() {
int id = GetSharedPref.getUserID(SplashActivity.this);
if (id > 0) {
startActivity(new Intent(SplashActivity.this,
SliderActivity.class));
overridePendingTransition(R.anim.zoomin, R.anim.fadeout);
finish();
} else {
startActivity(new Intent(SplashActivity.this,
ChooseActivity.class));
overridePendingTransition(R.anim.zoomin, R.anim.fadeout);
finish();
}

}
}, 3000);

}

public void registerDevice() {

// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);

// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(this);

registerReceiver(mHandleMessageReceiver, new IntentFilter(
DISPLAY_MESSAGE_ACTION));

// Get GCM registration id
final String regId = GCMRegistrar.getRegistrationId(this);

if (!regId.isEmpty()) {
SetSharedPref.setGCMID(SplashActivity.this, regId);
Toast.makeText(getApplicationContext(), regId, Toast.LENGTH_SHORT)
.show();
}

System.out.println("id: " + regId);

// Check if regid already presents
if (regId.equals("")) {
// Registration is not present, register now with GCM
GCMRegistrar.register(this, SENDER_ID);
} else {
// Device is already registered on GCM
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
Toast.makeText(getApplicationContext(),
"Already registered with GCM", Toast.LENGTH_LONG)
.show();
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {

@Override
protected Void doInBackground(Void... params) {
// Register on our server
// On server creates a new user

return null;
}

@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}

};
mRegisterTask.execute(null, null, null);
}
}

}

private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
// Waking up mobile if it is sleeping
WakeLocker.acquire(getApplicationContext());

/**
* Take appropriate action on this message depending upon your app
* requirement For now i am just displaying it on the screen
* */

// Showing received message

Toast.makeText(getApplicationContext(),
"New Message: " + newMessage, Toast.LENGTH_LONG).show();

// Releasing wake lock
WakeLocker.release();
}
};

@Override
protected void onDestroy() {
if (mRegisterTask != null) {
mRegisterTask.cancel(true);
}
try {
unregisterReceiver(mHandleMessageReceiver);
GCMRegistrar.onDestroy(this);
} catch (Exception e) {
Log.e("UnRegister Receiver Error", "> " + e.getMessage());
}
super.onDestroy();
}
}