Android Open Source - DialQuick_Android Main Activity






From Project

Back to project page DialQuick_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project DialQuick_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.blogspot.techzealous.ui;
//from   w  w w. j av  a2 s  .  com
import android.app.TabActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TabHost;

import com.blogspot.techzealous.dialquick.DialQuickConstants;
import com.blogspot.techzealous.dialquick.R;
import com.tapfortap.AdView;
import com.tapfortap.TapForTap;

public class MainActivity extends TabActivity {

  private Button buttonDialCall;
  private Button buttonSetNumber;
  private Button buttonShowMenu;
  private LinearLayout linearLayoutMenu;
  private TabHost myTabHost;
  private Button buttonExit;
  private Button buttonMoreApps;
  private SharedPreferences prefs;
    
  private boolean connection;
  private AdView ads;
  private ConnectivityManager cm;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        
        if(cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
          //code for TapForTap
          TapForTap.setDefaultAppId(DialQuickConstants.TAP_FOR_TAP_ID);
          TapForTap.checkIn(this);
          connection = true;
        }
         
        setContentView(R.layout.main_tab);
        
        //code for TapForTap
        ads = (AdView) findViewById(R.id.ad_view);
        if(connection) {
          ads.setVisibility(View.VISIBLE);
          ads.loadAds();
        }
        
        myTabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent i;
        
        i = new Intent(this, DQWellcome.class);
        spec = myTabHost.newTabSpec("wellcome").setIndicator("w").setContent(i);
        myTabHost.addTab(spec);
        
        i = new Intent(this, DialCallDialogActivity.class);
        spec = myTabHost.newTabSpec("mode").setIndicator("m").setContent(i);
        myTabHost.addTab(spec);
        
        i = new Intent(this, SetupPhoneActivity.class);
        spec = myTabHost.newTabSpec("phone").setIndicator("p").setContent(i);
        myTabHost.addTab(spec);
        
        myTabHost.setCurrentTab(0);
        
        
        prefs = PreferenceManager.getDefaultSharedPreferences(this);
        buttonDialCall = (Button) findViewById(R.id.buttonMainMode);
        buttonSetNumber = (Button) findViewById(R.id.buttonMainPhoneNumber);
        buttonMoreApps = (Button) findViewById(R.id.buttonMainMoreApps);
        buttonShowMenu = (Button) findViewById(R.id.buttonMainShowMenu);
        buttonExit = (Button) findViewById(R.id.buttonMainExit);
        linearLayoutMenu = (LinearLayout) findViewById(R.id.linearLayoutSideMenu);
               
        dialOrDisplayMainActivity();
        
        buttonDialCall.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            myTabHost.setCurrentTab(1);
            hideMenu();
            }
        });
        
        buttonSetNumber.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            myTabHost.setCurrentTab(2);
            hideMenu();
          }
        });
        
        buttonMoreApps.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:Emil Todorov"));
            startActivity(i);
          }
        });
        
        buttonShowMenu.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        hideMenu();
      }
    });
        
        buttonExit.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        finish();
      }
    });
        
    }
    
    private void hideMenu() {
      if(linearLayoutMenu.getVisibility() == View.VISIBLE) {
      linearLayoutMenu.setVisibility(View.GONE);
    } else {
      linearLayoutMenu.setVisibility(View.VISIBLE);
    }
    }
    
    public void onResume() {
      super.onResume();
            
      if(cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
          connection = true;
        //code for TapForTap
          ads.loadAds();
          ads.setVisibility(View.VISIBLE);
        }
    }
    
    public void onPause() {
      super.onPause();
      if(connection) {
        ads.stopLoadingAds();
        ads.setVisibility(View.GONE);
      }
    }
    
    /* If first start of the application, do not dial, else dial/call the PREF_TEL_NUMBER */
    private void dialOrDisplayMainActivity() {
      if(!prefs.getBoolean(DialQuickConstants.PREF_FIRST_START, true)) {
          if(prefs.getBoolean(DialQuickConstants.PREF_CALL, false)) {
            Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + prefs.getString(DialQuickConstants.PREF_TEL_NUMBER, "")));
            startActivity(i);
          } else {
            Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + prefs.getString(DialQuickConstants.PREF_TEL_NUMBER, "")));
            startActivity(i);
          }
        } else {
          prefs.edit().putBoolean(DialQuickConstants.PREF_FIRST_START, false).commit();
        }
    }

}




Java Source Code List

com.blogspot.techzealous.dialquick.DialQuickConstants.java
com.blogspot.techzealous.ui.ContactsActivity.java
com.blogspot.techzealous.ui.DQEula.java
com.blogspot.techzealous.ui.DQWellcome.java
com.blogspot.techzealous.ui.DialCallDialogActivity.java
com.blogspot.techzealous.ui.MainActivity.java
com.blogspot.techzealous.ui.SetupPhoneActivity.java