Friday, December 28, 2018

ProgressBar not shown due to animation disabled on phone | Android Programming


I noticed the ProgressBar used in my app suddenly stopped working.

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:progressDrawable="@drawable/circular_progress_bar"/>



res/drawable/circular_progress_bar.xml:

<?xml version="1.0" encoding="utf-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360">

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="7.0">

        <gradient
            android:centerColor="#2277DD"
            android:endColor="#2277DD"
            android:startColor="#2277DD"
            android:angle="0"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

I played with the code for an hour or so but cannot find out why. It turned out the reason is that I had turned off animation on my phone. To turn it back on, go to Settings/Developer options, find all the "animation scale" options and set the scales to a value other than "Animation off". Restart the app on the phone and the ProgressBar will come back.

Wednesday, December 26, 2018

Allow Microsoft Edge to visit self-signed HTTPS websites | Resolve certificate error issues | Microsoft Edge


If the website is using a self-signed certificate or an invalid certificate, Microsoft Edge shows an error page. Unlike Firefox or Google Chrome, it won't give you the choice of bypassing the error and continuing to the website.

To resolve this, one way is to make Edge trust the (self-signed) certificate. To do that, we follow 2 steps: 1) download the root certificate; 2) Import the root certificate. We have to download and import the root certificate because only importing the certificate for the website does not work as Edge will validate the whole path of the certificate. The details of the procedure are:

Step 1, download the root certificate:
  1. When seeing the Certificate Error page, click on the Certificate Error icon on the left side of the location bar of the browser.
  2. In the little popup, click on the View certificate link.
  3. In the Certification Information side window, the path of the certificate is posted.
  4. Click on the root certificate on the top. 
  5. At the bottom, there is an Export to file button. Click on the button to download the root certificate.
Step 2, import the root certificate
  1. Click on the Start menu of Windows 10.
  2. Input "Control Panel". In the middle of you keying in the words, the hints will show you the choice and you can select Control Panel from the list.
  3. At the top right side of the Control Panel, change the "View by:" option to "small icons".
  4. Find and click on the Internet Options icon.
  5. In the Internet Options dialog, select the Content tab.
  6. Find and click on the Certificate button.
  7. (Important!) Select the Trusted Root Certification Authorities tab.
  8. Click on the Import... button to import the downloaded root certificate.
 Notes:
  1. As we explained earlier, we need to import the root certificate. If there are intermediate certificates, you may need to import them too.
  2. If you are concerned to make such "unsafe" changes to your computer, you can download the Microsoft Edge VM (
    https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
    ), make the changes on the VM and play with it.

Stop showing soft keyboard on Activity start | Android programming


If the first element in the Activity is an EditText, it will get focus when the Activity starts, and the soft keyboard will show up.

There are many ways to solve this issue if you don't want the soft keyboard pop up. Here is a simple and interesting trick that only makes small updates on the layout XML files.

Add the attributes to the parent element of the first EditText. The EditText will not get focus at the start up and thus the soft keyboard will not show. The code to be added is highlighted below:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/some_iput"/>

   ...
 
Get This <