miércoles, 7 de febrero de 2018

Android Example: How to Implement Material Design Floating Action Menu

please check:

http://www.viralandroid.com/2016/02/android-floating-action-menu-example.html


Floating action menu is new concept which is used in mobile apps and websites. Nowadays some popular sites and apps have used floating action menu including inbox. It is used for quick action with multiple options like uploading photo, video, writing note etc. Floating action menu is useful for note taking application. In this tutorial, you will learn to add/implement material design floating action menu in your android application or game.

Using floating action menu helps to make clean and to increase content space in mobile app. One button is visible and when users click that button, other action buttons will appear there.

Android Example: How to Implement Material Design Floating Action Menu


This is simple task just you have to add some floating action buttons and make it as menu. Let's start by adding compile 'com.github.clans:fab:1.6.2' dependency in your app build.gradle file. Build.gradle file will look like below.

build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.github.clans:fab:1.6.2'
}
view rawbuild.gradle hosted with ❤ by GitHub

XML Layout File

Open your app XML layout file and add following XML code.

res/layout/ material_design_floating_action_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/material_design_android_floating_action_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="11dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#da3c2f"
fab:menu_colorPressed="#dc4b3f"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_label="Floating Action Menu"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/fab_add"
fab:menu_labels_colorNormal="#333"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#f2f1f1"
fab:menu_labels_textSize="15sp"
fab:menu_openDirection="up"
fab:menu_shadowColor="#66aff198"
fab:menu_shadowRadius="4dp"
fab:menu_shadowXOffset="1dp"
fab:menu_shadowYOffset="4dp"
fab:menu_showShadow="true">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_send"
fab:fab_label="Menu Item 1"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_photo"
fab:fab_label="Menu Item 2"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_edit"
fab:fab_label="Menu Item 3"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>


Java Activity File

Here, we controlled all about action menu item onclick. Following is the complete modified code of java activity file and you can add action to onclick listener according to your requirement.

src/ MaterialDesignFloatingActionMenu.java
package viralandroid.com.androidmaterialdesigntutorial;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.FloatingActionMenu;
public class MaterialDesignFloatingActionMenu extends AppCompatActivity {
FloatingActionMenu materialDesignFAM;
FloatingActionButton floatingActionButton1, floatingActionButton2, floatingActionButton3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.material_design_floating_action_menu);
materialDesignFAM = (FloatingActionMenu) findViewById(R.id.material_design_android_floating_action_menu);
floatingActionButton1 = (FloatingActionButton) findViewById(R.id.material_design_floating_action_menu_item1);
floatingActionButton2 = (FloatingActionButton) findViewById(R.id.material_design_floating_action_menu_item2);
floatingActionButton3 = (FloatingActionButton) findViewById(R.id.material_design_floating_action_menu_item3);
floatingActionButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO something when floating action menu first item clicked
}
});
floatingActionButton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO something when floating action menu second item clicked
}
});
floatingActionButton3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO something when floating action menu third item clicked
}
});
}
}


Now, run your Material Design Android Floating Action Menu Example application and click to the plus button then some other buttons will appear just above that plus button like the above screenshot.

jueves, 28 de diciembre de 2017

Playing Audio on Android from an HTML5 File

Please check: https://www.codeproject.com/Tips/677841/Playing-Audio-on-Android-from-an-HTML5-File
Introduction
Earlier today, I came across a problem. I have been working on an App in Android that displays HTML5 files from the assets folder inside a WebView. One of the big problems with playing Audio in an HTML5 page is that a lot of browsers do not support the <audio> tag; this includes several versions of the WebView control in different versions of Android. The bottom line is that you can't expect standardized results across different versions of Android when using the HTML5 <audio> tag. So we're going to use a workaround that uses the native Android method of playing audio.
Here is a synopsis of the paragraphs below that describe how to implement the code.
  • Configuring your WebView control
  • Creating an Audio Interface for the HTML5 web page
  • Attaching the Audio Interface to the WebView control
  • Invoking an Audio Interface function from the HTML5 page using JavaScript

Implementing the Code

Configuring your WebView control
Create a WebView control inside your layout. This is the XML code for the layout I used:
<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/webview"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent" />
This is the Java that I used to initially configure the WebView:
 //Configures the WebView during the onCreate method
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView myWebView = (WebView) findViewById(R.id.webview);

    //Set it to a webChromeClient
    myWebView.setWebChromeClient(new WebChromeClient());

    //the default for WebView is that JavaScript isn't enabled in WebView
    myWebView.getSettings().setJavaScriptEnabled(true);

    //the index.html file is placed in the assets folder
    myWebView.loadUrl("file:///android_asset/index.html");
}
Creating an Audio Interface for the HTML5 web page
Next, we're going to create an AudioInterface Java class to play audio MP3s from the assets folder.
Create a new Java Class and call it "AudioInterface.Java"
Here is the Java code for the class:
import java.io.IOException;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.webkit.JavascriptInterface;

public class AudioInterface {
 Context mContext;

 AudioInterface(Context c) {
  mContext = c;
 }
 
 //Play an audio file from the webpage
 @JavascriptInterface
 public void playAudio(String aud) { //String aud - file name passed 
                                     //from the JavaScript function
  final MediaPlayer mp;

     try {
      AssetFileDescriptor fileDescriptor = 
        mContext.getAssets().openFd(aud);
                                 mp = new MediaPlayer();
                                 mp.setDataSource(fileDescriptor.getFileDescriptor(), 
                                 fileDescriptor.getStartOffset(), 
                                 fileDescriptor.getLength());
                                 fileDescriptor.close();
                                 mp.prepare();
                                 mp.start();
     } catch (IllegalArgumentException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
              } catch (IllegalStateException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
              } catch (IOException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
           } 
 }
}
The above code creates a public method that accepts a string argument which is used as the URL for the mp3 file location. So I store my mp3 files in a sub folder in the assets folder called audio. So the playAudio method needs an argument similar to this: "audio/example.mp3". If it was stored directly in the assets folder it would look like this: "example.mp3".

Attaching the Audio Interface to the WebView control

Now, we need to attach the AudioInterface class to the WebView control in the onCreate method in order to make it available for the JavaScript code. So add the following code to the onCreate method we edited earlier in the layout's Java file:
myWebView.addJavascriptInterface(new AudioInterface(this), "AndAud");

Invoking an Audio Interface function from the HTML5 page using JavaScript

Now we can call the playAudio function from JavaScript inside the HTML5 file by using this method:
<script type="text/javascript">
 //AndAud is the alias of the AudioInterface class that we attached to the WebView
 AndAud.playAudio("audio/One.mp3");
</script> 
And that's it, it's kind of an annoying work around but at least you know it will work rather than waiting on the <audio> kinks to be worked out.

martes, 19 de diciembre de 2017

com.google.android.gms.ads.AdView could not be found Android Studio

Go on SDK Manager  > Extras > Select Google Repository and Google Play services and install them.


https://stackoverflow.com/questions/32657422/com-google-android-gms-ads-adview-could-not-be-found-android-studio

WEBVIEW ANDROID


1) Add component webView on your layout

activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com...MainActivity">
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="440dp"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="16dp" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>


2) use LoadUrl to show the content :
MainActivity.java
package com..;
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.webkit.WebView;


public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);
        WebView myWebView = (WebView) this.findViewById(R.id.webView);
        myWebView.loadUrl("http://https://jgvcodigo.blogspot.com/");
    }
}

3) You are going to need to add some permission to your Manifest:

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com..">
    <uses-permission android:name="android.permission.INTERNET" />
    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        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>    </application>
</manifest>








https://amatellanes.wordpress.com/2013/06/08/android-ejemplo-de-webview-en-android-parte-2/

miércoles, 13 de diciembre de 2017

Android Studio No USB devices detected

  1. First, enable debugger mode in your android device.
  2. Go to Device Manager from Start Menu and try to find ADB Interface with an error symbol on it. This generally happens because windows sometimes fail to load all the mobile device drives.
  3. Next, Go to http://adbdriver.com/downloads/ and download the driver installer, unzip and run it.
  4. Now go to Android Studio and you should find that everything is working fine.

https://stackoverflow.com/questions/37108864/android-studio-2-0-no-usb-devices-detected

lunes, 4 de diciembre de 2017

Android Studio continues to get a Unsupported major.minor version 52.0

En

File->Other Settings->Default Project Structure->JDK Location (cambia a la ultima version para mi fue jdk1.8.0_92)