Android Open Source - android.app.niuz.io Pre Main Activity






From Project

Back to project page android.app.niuz.io.

License

The source code is released under:

GNU General Public License

If you think the Android project android.app.niuz.io 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 io.niuz;
/*from w w w. j av  a2 s .  c o m*/
import io.niuz.model.APIRetrievalStatus;
import io.niuz.services.PhoneService;
import io.niuz.services.UserService;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;

//https://kuler.adobe.com/JR-01-Cool-color-theme-3904982/edit/?copy=true
public class PreMainActivity extends Activity {
  private Button pmaContinue;
  private Button pmaRestart;
  
  private Context context;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pre_main);
    this.context = this;    
    
    // Enabling sync HTTP posting
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); 
    
    // Setting up the phone number
    PhoneService.initPhoneNumber(this.getApplicationContext());
    if (PhoneService.getPhoneNumber() == null) {
      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
      alertDialogBuilder.setTitle("Fatal error");
      alertDialogBuilder
        .setMessage("Your device does not have neither IMEI, nor MEID, nor ESN codes. Please try using a "
          + "different device. Preferably it should be a mobile device.\n\nWe are sorry for any "
          + "inconvenience caused.")
        .setCancelable(false)
        .setPositiveButton("Okay...",new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
            finish();
          }
          });
      alertDialogBuilder.create().show();
    }
    
    // Continue button
    this.pmaContinue = (Button)findViewById(R.id.pmaContinue);
    pmaContinue.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        transferToMainActivity();
      }
    });
    
    // Restart all button
    this.pmaRestart = (Button)findViewById(R.id.pmaRestart);
    pmaRestart.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        toast("Reinitializing user data, please wait...");
        pmaContinue.setClickable(false);
        pmaRestart.setClickable(false);
        new ReinitializeAllTask().execute();
      }
    });
  }
  
  private void transferToMainActivity() {
    startActivity(new Intent(this, MainActivity.class));
  }
  
  private void toast(String message) {
    PhoneService.toast(message, this);
  }
  
  private class ReinitializeAllTask extends AsyncTask<Object, Object, APIRetrievalStatus> {

    @Override
    protected APIRetrievalStatus doInBackground(Object... arg0) {
      try {
        UserService.deleteUser(context);
        return APIRetrievalStatus.SUCCESS; 
        
      } catch (Exception e) {
        return APIRetrievalStatus.ERROR;
      }
    }
    
    @Override
    protected void onPostExecute(APIRetrievalStatus result) {
      switch (result) {
      case SUCCESS:
        toast("Server updated");
        transferToMainActivity();
        break;

      case ERROR:
        toast("Failed to reinitialize user in the server! Please manually restart the application");
      }
    }
  }
  
  @Override
  public void onBackPressed() {
    startActivity(new Intent(context, PreMainActivity.class));
  }
}




Java Source Code List

io.niuz.CategoriesSelectionActivity.java
io.niuz.CompanyInformationLoadingActivity.java
io.niuz.MainActivity.java
io.niuz.NewsCompaniesSelectionActivity.java
io.niuz.NewsHeadersActivity.java
io.niuz.NewsReaderActivity.java
io.niuz.PreMainActivity.java
io.niuz.model.APIRetrievalStatus.java
io.niuz.model.CategoryInformation.java
io.niuz.model.CompanyInformation.java
io.niuz.model.InitUserStatus.java
io.niuz.model.News.java
io.niuz.services.BaseService.java
io.niuz.services.CategoriesSubcategoriesService.java
io.niuz.services.CompaniesService.java
io.niuz.services.NewsService.java
io.niuz.services.PhoneService.java
io.niuz.services.UserService.java