/**
   * Use strict mode to determine app bottlenecks.
   *
   * <p>Does nothing if api version is less than 11.
   */
  @TargetApi(11)
  private static void initStrictMode() {

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
      return;
    }

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .detectCustomSlowCalls()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()
            .penaltyLog()
            .penaltyFlashScreen()
            .build());

    try {
      StrictMode.setVmPolicy(
          new StrictMode.VmPolicy.Builder()
              .detectLeakedSqlLiteObjects()
              .detectLeakedClosableObjects()
              .setClassInstanceLimit(Class.forName(PlaybackService.class.getName()), 1)
              .penaltyLog()
              .build());
    } catch (ClassNotFoundException e) {
      Log.e(TAG, e.toString());
    }
  }
  @SuppressLint("UseSparseArrays")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    scanResultsMapByChannel = new HashMap<Integer, List<ScanResult>>();
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    currentSSID = wifiInfo.getSSID();
    splitScanResultByChannel();

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    int minDeviceCounts = Integer.MAX_VALUE;
    int channelOnMinDeviceCounts = -1;

    for (Integer channel : scanResultsMapByChannel.keySet()) {
      List<ScanResult> singleScanResultList = scanResultsMapByChannel.get(channel);
      int size = singleScanResultList.size();
      if (minDeviceCounts > size) {
        minDeviceCounts = size;
        channelOnMinDeviceCounts = channel;
      }
    }

    // TODO:post change the router to channelOnMinDeviceCounts
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);

    helper = new Helper(getActivity());

    // Hashmap for retrieved locations
    // (I am passing the right map from inside this one to AsyncTask's onPostExecute and then to
    // updateForecastOnUi).
    retrievedLocationsList = new ArrayList<HashMap<String, String>>();

    // build the SimpleDateFormat here to use it everywhere as it is
    sdf = new SimpleDateFormat("yyyy MM dd HH z");
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

    // create a HashMap of date and ids (String) to compare dates and find the nearest date
    dates = new HashMap<Date, String>();

    // fix strict mode network exception
    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    // get the current location
    setUpLocationClientIfNeeded();
    if (!mLocationClient.isConnected()) {
      mLocationClient.connect();
    }
  }
  public void UpdateStudentStatus(int student_status) {

    if (Build.VERSION.SDK_INT > 7) {

      StrictMode.ThreadPolicy myPolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(myPolicy);
    }

    //  Connect and Post

    try {

      ArrayList<NameValuePair> objNameValuePairs = new ArrayList<NameValuePair>();
      objNameValuePairs.add(
          new BasicNameValuePair("student_status", String.valueOf(student_status)));

      HttpClient objHttpClient = new DefaultHttpClient();
      HttpPost objHttpPost = new HttpPost("http://gexam.esy.es/GExam/db_add_data.php");
      objHttpPost.setEntity(new UrlEncodedFormEntity(objNameValuePairs, "UTF-8"));
      objHttpClient.execute(objHttpPost);

      Log.d("GExam", "String score = " + String.valueOf(score));

    } catch (Exception e) {

      Log.d("GExam", "Connect and Post Error ====>" + e.toString());
    }
  } //  end of AddScoreToMySQL
  public void AddStudentChoiceToMySQL(
      int course_id, int std_id, int question_id, int student_ans_id) {

    if (Build.VERSION.SDK_INT > 7) {

      StrictMode.ThreadPolicy myPolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(myPolicy);
    }

    //  Connect and Post

    try {

      ArrayList<NameValuePair> objNameValuePairs = new ArrayList<NameValuePair>();
      objNameValuePairs.add(new BasicNameValuePair("course_id", String.valueOf(course_id)));
      objNameValuePairs.add(new BasicNameValuePair("std_id", String.valueOf(std_id)));
      objNameValuePairs.add(new BasicNameValuePair("question_id", String.valueOf(question_id)));
      objNameValuePairs.add(
          new BasicNameValuePair("student_ans_id", String.valueOf(student_ans_id)));

      HttpClient objHttpClient = new DefaultHttpClient();
      HttpPost objHttpPost = new HttpPost("http://gexam.esy.es/GExam/db_add_data.php");
      objHttpPost.setEntity(new UrlEncodedFormEntity(objNameValuePairs, "UTF-8"));
      objHttpClient.execute(objHttpPost);

      Log.e("GExam", "course_id " + course_id);
      Log.e("GExam", "std_id " + std_id);
      Log.e("GExam", "question_id " + question_id);
      Log.e("GExam", "student_ans_id " + student_ans_id);

    } catch (Exception e) {

      Log.e("GExam", "Connect and Post Error ====>" + e.toString());
    }
  } //  end of AddScoreToMySQL
  private void updateToMySQL() {

    // Setup policy
    StrictMode.ThreadPolicy myPolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(myPolicy);

    // Update Value
    try {

      ArrayList<NameValuePair> objNameValuePairs = new ArrayList<NameValuePair>();
      objNameValuePairs.add(new BasicNameValuePair("isAdd", "true"));
      // objNameValuePairs.add(new BasicNameValuePair("idUser", strIDUser));
      objNameValuePairs.add(new BasicNameValuePair("Sleep", sleepString));
      objNameValuePairs.add(new BasicNameValuePair("Breakfast", breakfastString));
      objNameValuePairs.add(new BasicNameValuePair("Lunch", lunchString));
      objNameValuePairs.add(new BasicNameValuePair("Dinner", dinnerString));
      objNameValuePairs.add(new BasicNameValuePair("TypeExercise", typeExerciseString));
      objNameValuePairs.add(new BasicNameValuePair("TimeExercise", timeExerciseString));
      objNameValuePairs.add(new BasicNameValuePair("DrinkWater", drinkWaterString));
      objNameValuePairs.add(new BasicNameValuePair("Weight", weightString));
      objNameValuePairs.add(new BasicNameValuePair("NameUser", strNameUser));

      HttpClient objHttpClient = new DefaultHttpClient();
      HttpPost objHttpPost = new HttpPost("http://swiftcodingthai.com/tae/add_data_record_tae.php");
      objHttpPost.setEntity(new UrlEncodedFormEntity(objNameValuePairs, "UTF-8"));
      objHttpClient.execute(objHttpPost);

      Toast.makeText(RecordActivity.this, "Update New Value Successful", Toast.LENGTH_LONG);

      finish();

    } catch (Exception e) {
      Toast.makeText(RecordActivity.this, "Cannot Update To MySQL", Toast.LENGTH_LONG).show();
    }
  } // UpdateToMySQL
Example #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_load_screen);

    Thread splashThread =
        new Thread() {

          @Override
          public void run() {
            try {
              int waited = 0;
              while (waited < 3000) {
                sleep(100);
                waited += 100;
              }
            } catch (InterruptedException e) {
              // do nothing
            } finally {
              finish();
              Intent intent = new Intent(LoadScreen.this, MainActivity.class);
              startActivity(intent);
            }
          }
        };
    splashThread.start();
  }
Example #8
0
  /**
   * Enables strict mode. This should only be called when debugging the application and is useful
   * for finding some potential bugs or best practice violations.
   */
  @TargetApi(11)
  public static void enableStrictMode() {
    // Strict mode is only available on gingerbread or later
    if (Utils.hasGingerbread()) {

      // Enable all thread strict mode policies
      StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
          new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog();

      // Enable all VM strict mode policies
      StrictMode.VmPolicy.Builder vmPolicyBuilder =
          new StrictMode.VmPolicy.Builder().detectAll().penaltyLog();

      // Honeycomb introduced some additional strict mode features
      if (Utils.hasHoneycomb()) {
        // Flash screen when thread policy is violated
        threadPolicyBuilder.penaltyFlashScreen();
        // For each activity class, set an instance limit of 1. Any more instances and
        // there could be a memory leak.
        /* vmPolicyBuilder
        .setClassInstanceLimit(ContactActivity.class, 1);*/
      }

      // Use builders to enable strict mode policies
      StrictMode.setThreadPolicy(threadPolicyBuilder.build());
      StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
  }
    public int appNotResponding(String processName, int pid, String processStats) {
      if (mVerbose > 0) {
        StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
        System.err.println("// NOT RESPONDING: " + processName + " (pid " + pid + ")");
        System.err.println(processStats);
        StrictMode.setThreadPolicy(savedPolicy);
      }

      synchronized (Monkey.this) {
        mRequestAnrTraces = true;
        mRequestDumpsysMemInfo = true;
        mRequestProcRank = true;
        if (mRequestBugreport) {
          mRequestAnrBugreport = true;
          mReportProcessName = processName;
        }
      }
      if (!mIgnoreTimeouts) {
        synchronized (Monkey.this) {
          mAbort = true;
        }
        return (mKillProcessAfterError) ? -1 : 0;
      }
      return 0;
    }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    if (twitter == null) {
      twitter = new TwitterFactory().getInstance();
    }
    if (accessToken == null) {
      loginToTwitter();
    }

    actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Tab tab1 = actionBar.newTab();
    tab1.setText("ListView");
    tab1.setTabListener(new MyTabListener(first));

    Tab tab2 = actionBar.newTab();
    tab2.setText("Images");
    tab2.setTabListener(new MyTabListener(second));

    Tab tab3 = actionBar.newTab();
    tab3.setText("Tweets");
    tab3.setTabListener(new MyTabListener(third));

    actionBar.addTab(tab1);
    actionBar.addTab(tab2);
    actionBar.addTab(tab3);
  }
    public boolean appCrashed(
        String processName,
        int pid,
        String shortMsg,
        String longMsg,
        long timeMillis,
        String stackTrace) {
      if (mVerbose > 0) {
        StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
        System.err.println("// CRASH: " + processName + " (pid " + pid + ")");
        System.err.println("// Short Msg: " + shortMsg);
        System.err.println("// Long Msg: " + longMsg);
        System.err.println("// Build Label: " + Build.FINGERPRINT);
        System.err.println("// Build Changelist: " + Build.VERSION.INCREMENTAL);
        System.err.println("// Build Time: " + Build.TIME);
        System.err.println("// " + stackTrace.replace("\n", "\n// "));
        StrictMode.setThreadPolicy(savedPolicy);
      }

      if (!mIgnoreCrashes || mRequestBugreport) {
        synchronized (Monkey.this) {
          if (!mIgnoreCrashes) {
            mAbort = true;
          }
          if (mRequestBugreport) {
            mRequestAppCrashBugreport = true;
            mReportProcessName = processName;
          }
        }
        return !mKillProcessAfterError;
      }
      return false;
    }
Example #12
0
  public void initializeMainWork() {
    mContext = getApplicationContext();
    // StricMode Thread Policy setting
    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .permitDiskReads()
            .permitDiskWrites()
            .permitNetwork()
            .build());
    select_icon = (Button) findViewById(R.id.select_icon);
    select_icon.setOnClickListener(this);

    mAddress = new MyAddress();
    mAddress.getAddressFromText();
    if (!mAddress.getIP().equals("")
        && !mAddress.getPORTDATA().equals("")
        && !mAddress.getPORTVIDEO().equals("")) {
      SIP = mAddress.getIP();
      DATA_SPORT = mAddress.getPORTDATA();
      VIDEO_SPORT = mAddress.getPORTVIDEO();
      editText3.setText(SIP);
      editText4.setText(DATA_SPORT);
      editText5.setText(VIDEO_SPORT);
      CONNECTION_READY = true;
    }

    mUser = new MyUser();

    img_lock = (ImageView) findViewById(R.id.image_lock);
    img_unlock = (ImageView) findViewById(R.id.image_unlock);
    img_lock.setOnClickListener(this);
    img_unlock.setOnClickListener(this);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie_details_page);

    fanart_play = (ImageView) findViewById(R.id.imageViewFanartPlay);
    plot_txt = (TextView) findViewById(R.id.textViewPlot);
    imdb_txt = (TextView) findViewById(R.id.textViewIMDBscore);
    button = (Button) findViewById(R.id.button_start);

    MyOnClickListener Listener = new MyOnClickListener();
    fanart_play.setOnClickListener(Listener);

    Bundle b = getIntent().getExtras();

    fanart_path = b.getString("fanart_path");
    plot = b.getString("plot");
    imdb_score = b.getString("imdb_score");
    movieid = Integer.parseInt(b.getString("movieid"));

    String fanart = "http://192.168.1.128/" + fanart_path;
    plot_txt.setText(plot);
    imdb_txt.setText(imdb_score + "/10");

    Picasso.with(getApplicationContext())
        .load(fanart)
        .transform(new OverlayTransformation())
        .placeholder(R.drawable.fanart_placeholder)
        .error(R.drawable.fanart_placeholder)
        .into(fanart_play);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
  }
Example #14
0
  public static String Gethttprequest() {

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    HttpClient httpclient = new DefaultHttpClient();
    String url = utility.HostAdress;
    HttpGet request = new HttpGet(url + "events");
    // replace with your url

    HttpResponse response;
    try {
      response = httpclient.execute(request);
      String s = EntityUtils.toString(response.getEntity());

      return s;
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    }
  }
Example #15
0
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.activity_fragment_news, container, false);

    listView = (ListView) rootView.findViewById(R.id.newsListView);

    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    try {
      XMLPullParserHandler parser = new XMLPullParserHandler();
      items = parser.parse(XML_URL);
      NewsListAdapter adapter =
          new NewsListAdapter(this.getActivity(), R.layout.news_listrow_details, items);
      listView.setAdapter(adapter);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    }

    listView.setOnItemClickListener(this);
    return rootView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    if (MyApplication.debug) {
      StrictMode.setThreadPolicy(
          new StrictMode.ThreadPolicy.Builder()
              .detectDiskReads()
              .detectDiskWrites()
              .detectNetwork() // or .detectAll() for all detectable problems
              .penaltyLog()
              .build());
      StrictMode.setVmPolicy(
          new StrictMode.VmPolicy.Builder()
              .detectLeakedSqlLiteObjects()
              // .detectLeakedClosableObjects()
              .penaltyLog()
              .penaltyDeath()
              .build());
    }

    super.onCreate(savedInstanceState);
    MyApplication.getInstance().getSettings().registerOnSharedPreferenceChangeListener(this);
    setLanguage();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
  }
  private String readFile(String file, char endChar) {
    // Permit disk reads here, as /proc/meminfo isn't really "on
    // disk" and should be fast.  TODO: make BlockGuard ignore
    // /proc/ and /sys/ files perhaps?
    StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
    FileInputStream is = null;
    try {
      is = new FileInputStream(file);
      int len = is.read(mBuffer);
      is.close();

      if (len > 0) {
        int i;
        for (i = 0; i < len; i++) {
          if (mBuffer[i] == endChar) {
            break;
          }
        }
        return new String(mBuffer, 0, i);
      }
    } catch (java.io.FileNotFoundException e) {
    } catch (java.io.IOException e) {
    } finally {
      IoUtils.closeQuietly(is);
      StrictMode.setThreadPolicy(savedPolicy);
    }
    return null;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.inject(this);

    // Config Strict Mode
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);

    checkLogin();

    _loginButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            login();
          }
        });

    _signupLink.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // Start the Signup activity
            Intent intent = new Intent(getApplicationContext(), SignupActivity.class);
            startActivityForResult(intent, REQUEST_SIGNUP);
          }
        });
  }
Example #19
0
  public static int UserMatch() throws IOException, JSONException {
    if (android.os.Build.VERSION.SDK_INT > 9) {

      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

      StrictMode.setThreadPolicy(policy);
    }

    OkHttpClient client = new OkHttpClient();

    RequestBody formBody =
        new FormBody.Builder().add("username", username).add("password", password).build();
    Request request =
        new Request.Builder()
            .url("http://projetdeweb.azurewebsites.net/API/Connection/Connect")
            .post(formBody)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

    System.out.println(response.body().string());

    int Rights = -1;
    JSONArray jsonArray = new JSONArray(response.body().string());
    for (int i = 0; i < jsonArray.length(); i++) {
      JSONObject jsonObject = jsonArray.getJSONObject(i);
      Rights = jsonObject.optInt("Rights");
    }

    return Rights;
  }
 private static void tryObtainingDataDirLockOrDie() {
   StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
   StrictMode.allowThreadDiskWrites();
   try {
     String dataPath = PathUtils.getDataDirectory(ContextUtils.getApplicationContext());
     File lockFile = new File(dataPath, EXCLUSIVE_LOCK_FILE);
     boolean success = false;
     try {
       // Note that the file is not closed intentionally.
       RandomAccessFile file = new RandomAccessFile(lockFile, "rw");
       sExclusiveFileLock = file.getChannel().tryLock();
       success = sExclusiveFileLock != null;
     } catch (IOException e) {
       Log.w(TAG, "Failed to create lock file " + lockFile, e);
     }
     if (!success) {
       Log.w(
           TAG,
           "The app may have another WebView opened in a separate process. "
               + "This is not recommended and may stop working in future versions.");
     }
   } finally {
     StrictMode.setThreadPolicy(oldPolicy);
   }
 }
Example #21
0
  @SuppressLint("NewApi")
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    StrictMode.ThreadPolicy poly = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(poly);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.changepassword);
    mkc = (EditText) findViewById(R.id.editmkht);
    mkm = (EditText) findViewById(R.id.editmkm);
    lmkm = (EditText) findViewById(R.id.editlmkm);
    btnluu = (Button) findViewById(R.id.btnluu);
    btnluu.setOnClickListener(
        new OnClickListener() {

          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String mkht = mkc.getText().toString();
            String mkm1 = mkm.getText().toString();
            String lmkm1 = lmkm.getText().toString();
            List<NameValuePair> name = new ArrayList<NameValuePair>();
            name.add(new BasicNameValuePair("MatKhau", mkht));
            name.add(new BasicNameValuePair("MatKhauMoi", lmkm1));
            jSon js = new jSon();
            JSONObject ob =
                js.getJSONFromUrl("http://minh1.comyr.com/new/UpdateMK.php", "POST", name);
            Toast.makeText(getApplicationContext(), "Thành Công!...", Toast.LENGTH_LONG).show();
          }
        });
  }
Example #22
0
  /** enables "strict mode" for testing - should NEVER be used in release builds */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private static void enableStrictMode() {
    // return if the build is not a debug build
    if (!BuildConfig.DEBUG) {
      AppLog.e(T.UTILS, "You should not call enableStrictMode() on a non debug build");
      return;
    }

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()
            .penaltyLog()
            .penaltyFlashScreen()
            .build());

    StrictMode.setVmPolicy(
        new StrictMode.VmPolicy.Builder()
            .detectActivityLeaks()
            .detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects()
            .detectLeakedRegistrationObjects() // <-- requires Jelly Bean
            .penaltyLog()
            .build());

    AppLog.w(T.UTILS, "Strict mode enabled");
  }
Example #23
0
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.i("TAG", "------------------------ Restart");
    // LocationManager locationManager = (LocationManager)
    // getSystemService(Context.LOCATION_SERVICE);
    // LocationProvider locationProvider =
    // locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
    // Or, use GPS location data:
    // LocationProvider locationProvider = LocationManager.GPS_PROVIDER;

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()
            .penaltyLog()
            .build());
    StrictMode.setVmPolicy(
        new StrictMode.VmPolicy.Builder()
            .detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects()
            .penaltyLog()
            .penaltyDeath()
            .build());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_loading);
    progressBar = (ProgressBar) findViewById(R.id.progressBar1);
    textView = (TextView) findViewById(R.id.textView1);
    textView.setText(R.string.application_name);
    ReadJson readJson = new ReadJson();
    readJson.execute();
  }
    public JSONObject getJSONFromURL() {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);

      HttpResponse response;
      HttpClient myClient = new DefaultHttpClient();
      HttpPost myConnection = new HttpPost(urlIan);

      try {
        response = myClient.execute(myConnection);
        test = EntityUtils.toString(response.getEntity(), "UTF-8");
        arr = new JSONArray(test);
        strRoot = arr.getJSONObject(0);
        finished = true;

      } catch (IOException e) {
        // Toast.makeText(getApplicationContext(), "error1: "+e.toString(),
        // Toast.LENGTH_LONG).show();
      } catch (JSONException e) {
        // Toast.makeText(getApplicationContext(), "error2: "+e.toString(),
        // Toast.LENGTH_LONG).show();
      }

      startProgressBar();
      return strRoot;
    }
Example #25
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTitle("codeforces monitor");

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Button refreshButton = (Button) findViewById(R.id.refreshButton);
    refreshButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            updateList();
          }
        });

    Button aboutButton = (Button) findViewById(R.id.aboutButton);
    aboutButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, AboutActivity.class));
          }
        });

    Button listButton = (Button) findViewById(R.id.listButton);
    listButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, ListActivity.class));
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .detectCustomSlowCalls()
            .detectDiskWrites()
            .penaltyDialog()
            .build());

    button = (Button) findViewById(R.id.buttonBlocked);
    button.setOnClickListener(this);

    ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
    co.hideOnClickOutside = true;
    sv =
        ShowcaseView.insertShowcaseView(
            R.id.buttonBlocked,
            this,
            "ShowcaseView Sample",
            "When the ShowcaseView is showing, "
                + "pressing the button will show a gesture. When it is hidden "
                + "it'll go to another Activity.",
            co);
    sv.setOnShowcaseEventListener(this);
  }
Example #27
0
 @Override
 public void onCreate() {
   super.onCreate();
   if (Config.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
     StrictMode.setThreadPolicy(
         new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
     StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
   }
   sInstance = this;
   initImageLoader(getApplicationContext());
   mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
   mPreferences.registerOnSharedPreferenceChangeListener(this);
   try {
     ViewConfiguration config = ViewConfiguration.get(this);
     Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
     if (menuKeyField != null) {
       menuKeyField.setAccessible(true);
       menuKeyField.setBoolean(config, false);
     }
   } catch (Exception ex) {
     // Ignore
   }
   // 全局异常捕获
   //		CustomException customException = CustomException.getInstance();
   //		customException.init(getApplicationContext());
   initJpush();
 }
Example #28
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // by jmpessoa --- fix for http get
    // ref. http://stackoverflow.com/questions/8706464/defaulthttpclient-to-androidhttpclient
    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    // Log.i("jApp","01.Activity.onCreate");
    controls = new Controls();
    controls.activity = this;
    controls.appLayout = new RelativeLayout(this);
    controls.appLayout.getRootView().setBackgroundColor(0x00FFFFFF);
    controls.screenStyle = controls.jAppOnScreenStyle();
    switch (controls.screenStyle) {
      case 1:
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
      case 2:
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        break;
      default:; // Device Default , Rotation by Device
    }
    this.setContentView(controls.appLayout);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    // Event : Java -> Pascal
    // Log.i("jApp","02.Controls.jAppOnCreate");
    controls.jAppOnCreate(this, controls.appLayout);
  }
  @Override
  public void onCreate() {
    super.onCreate();

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDialog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
  }
Example #30
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    setContentView(R.layout.activity_rssfeed);
  }