Back to project page OneClickCall.
The source code is released under:
GNU General Public License
If you think the Android project OneClickCall listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.iisaint.oneclickcall; //from w ww . j a va2 s. c o m import android.net.Uri; import android.os.Bundle; import android.provider.BaseColumns; import android.provider.CallLog; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.database.Cursor; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { private static final String TAG = "MAIN"; private static final int ABOUT = 0; private EditText number = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); number = (EditText) findViewById(R.id.number); Bundle bundle = this.getIntent().getExtras(); if(bundle != null){ Log.d(TAG, "bundle!=null"); String call = bundle.getString("PHONE_NUMBER"); if(call != null){ Log.d(TAG, "call!=null"); Intent intentDial = new Intent("android.intent.action.CALL",Uri.parse("tel:"+call)); startActivity(intentDial); Log.d(TAG, "dial return"); finish(); Log.d(TAG, "finish"); System.exit(0); } else Log.d(TAG, "call==null"); } else{ Log.d(TAG, "bundle==null"); } String CALLS_COUNT = "calls_count"; String[] projection = new String[] { BaseColumns._ID, CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.DURATION, CallLog.Calls.TYPE, CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_TYPE, CallLog.Calls.CACHED_NUMBER_LABEL }; String temp = CallLog.Calls.TYPE + " = " +CallLog.Calls.OUTGOING_TYPE;// + ") GROUP BY (" + CallLog.Calls.NUMBER; Log.d(TAG, temp); String[] selection = new String[]{""}; Log.d(TAG, "b123"); Cursor countCursor = getContentResolver().query(Uri.parse("content://call_log/calls"), projection, temp, null, CallLog.Calls.DEFAULT_SORT_ORDER); Log.d(TAG, CallLog.Calls.DEFAULT_SORT_ORDER); Log.d(TAG, "# of " + countCursor.getCount()); String top1_Name = ""; String top1_Number = ""; int num = 0; int round = 30; Cursor tempCur = null; while(countCursor.moveToNext() && round > 0){ if(!countCursor.getString(1).equalsIgnoreCase(top1_Number)){ Log.i(TAG,"in "+num); String aaa = CallLog.Calls.NUMBER + " = ?"; String[] paras = {countCursor.getString(1)}; Log.i(TAG, aaa); tempCur = getContentResolver().query(Uri.parse("content://call_log/calls"), new String[]{BaseColumns._ID, CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME}, aaa, paras, CallLog.Calls.DEFAULT_SORT_ORDER); Log.i(TAG, "tempCur count = " + tempCur.getCount()); if(tempCur.getCount() > num){ num = tempCur.getCount(); tempCur.moveToNext(); top1_Name = tempCur.getString(2); top1_Number = tempCur.getString(1); Log.i(TAG, "name = " + top1_Name + ", " + num); } tempCur.close(); round--; } } number.setText(top1_Number); number.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { number.setText(""); } } ); //Add listener to add shortcut button Button create = (Button) findViewById(R.id.create); create.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(number.getText().length() != 0){ addShortcut(number.getText().toString()); finish(); System.exit(0); } else{ TextView result = (TextView) findViewById(R.id.warning); result.setText("Please Input Number!"); } } }); //TODO : Add listener to removeAll shortcut button Button removeAll = (Button) findViewById(R.id.removeAll); removeAll.setVisibility(View.INVISIBLE); removeAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeShortcut(number.getText().toString()); finish(); System.exit(0); } }); } private void addShortcut(String number) { //Adding shortcut for MainActivity //on Home screen Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Bundle bundle = new Bundle(); bundle.putString("PHONE_NUMBER", number); shortcutIntent.putExtras(bundle); Intent addIntent = new Intent(); addIntent .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, number); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.occ)); addIntent .setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getApplicationContext().sendBroadcast(addIntent); } private void removeShortcut(String number) { //Adding shortcut for MainActivity //on Home screen Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); //addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, number); addIntent .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); getApplicationContext().sendBroadcast(addIntent); } private void showAbout() { // Inflate the about message contents View messageView = getLayoutInflater().inflate(R.layout.about, null, false); // When linking text, force to always use default color. This works // around a pressed color state bug. /* TextView textView = (TextView) messageView.findViewById(R.id.about_credits); int defaultColor = textView.getTextColors().getDefaultColor(); textView.setTextColor(defaultColor); */ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(R.drawable.ic_launcher); builder.setTitle(R.string.app_name); builder.setView(messageView); builder.create(); builder.show(); } @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 onMenuItemSelected(int featureId, MenuItem item) { switch(featureId){ case ABOUT: showAbout(); break; } return super.onMenuItemSelected(featureId, item); } }