I develop a high performance program to generate optimal addition chains. An addition chain is a sequence of numbers starting with 1 where each element in the sequence apart from the first is the sum of two prior elements. Optimal chains for a given target (the last value in the sequence) have the smallest number of elements and must be strictly increasing. In a simple implementation of a program (my actual program uses a different method) if we have a sequence of a_0,a_1,...,a_i we want to find all a_{i+1} = a_j + a_k > a_i with i >= j >= k >= 0 . We also typically know bounds calculated up front such that a_{i+1} >= b_{i+1}. It helps performance to eliminate duplicate a_{i+1} values since the same number can be created in multiple ways. For example:

1 2 3 4=(2+2 or 3+1)

It only just occurred to me (despite it being so simple) that you can eliminate duplicates fast by merging these streams of numbers:

s1: a_i + a_i, a_i + a_{i-1}, a_i + a_{i-2} + ... + a_i + a_0

s2: a_{i-1} + a_{i-1}, a_{i-1} + a_{i-2}, a_{i-1} + a_{i-3} + ... + a_{i-1} + a_0

s3: a_{i-2} + a_{i-2}, a_{i-2} + a_{i-3}, a_{i-2} + a_{i-4} + ... + a_{i-2} + a_0

...

It turns out the number of these streams is very limited by the mathematics. Having the element a_{i+1} be generated in decreasing order really helps with some optimizations and as a heuristic searching first using higher numbers is very effective. I would need to generalize this idea to handle sums of more than two prior elements. So for example I would want to merge all pair sums with all triplet sums etc. Once again though the maximal number of prior elements in each sum is very limited by the mathematics. I don't currently eliminate duplicates in the fastest algorithm but this is likely a good optimization if I can do it at a low enough cost.

So my question is has anyone seem similar things done in other domains?

I have an app with an automatically generated navigation drawer. Now I want to add some swipe views just like the app from the screenshot, but I don't exactly know how to do that.

Thanks for your help.

I'm working a Earthquake Reporting app and I have added permissions to the manifest file for both INTERNET and ACCESS_NETWORK_STATE. I went into the emulator's settings and developer's settings and made sure all the network settings were set appropriately. I've researched the question here & tried those suggestions which did not work for me. I also saw where others had this issue due to the firewall. I am running Norton, however their fix instructions were, ahem, over my head. Something about setting the proxy in Android Studio - either from the command line or from the Settings > HTTP Proxy dialog box. There, I have "Auto-detect proxy settings" selected. If I were to configure the proxy settings manually, I would not know what to input for the information. If anyone has any suggestions as to how I might fix this (I did cleans & rebuilds, this is day two on this issue) please share!

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

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

    <activity android:name=".EarthquakeActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
 App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

public class EarthquakeActivity extends AppCompatActivity
    implements LoaderManager.LoaderCallbacks<List<Earthquake>> {

private static final String LOG_TAG = EarthquakeActivity.class.getName();

/** URL for earthquake data from the USGS dataset */
private static final String USGS_REQUEST_URL =
        "http://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&orderby=time&minmag=6&limit=10";

private static final int EARTHQUAKE_LOADER_ID = 1;

/** Adapter for the list of earthquakes */
private EarthquakeAdapter mAdapter;

/** TextView that is displayed when the list is empty */
private TextView mEmptyStateTextView;

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

    // Find a reference to the {@link ListView} in the layout
    ListView earthquakeListView = (ListView) findViewById(R.id.list);

    mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
    earthquakeListView.setEmptyView(mEmptyStateTextView);

    // Create a new adapter that takes an empty list of earthquakes as input
    mAdapter = new EarthquakeAdapter(this, new ArrayList<Earthquake>());

    // Set the adapter on the {@link ListView}
    // so the list can be populated in the user interface
    earthquakeListView.setAdapter(mAdapter);

    // Set an item click listener on the ListView, which sends an intent to a web browser
    // to open a website with more information about the selected earthquake.
    earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // Find the current earthquake that was clicked on
            Earthquake currentEarthquake = mAdapter.getItem(position);

            // Convert the String URL into a URI object (to pass into the Intent constructor)
            Uri earthquakeUri = Uri.parse(currentEarthquake.getUrl());

            // Create a new intent to view the earthquake URI
            Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUri);

            // Send the intent to launch a new activity
            startActivity(websiteIntent);
        }
    });



    // Get a reference to the ConnectivityManager to check state of network connectivity
    ConnectivityManager connMgr = (ConnectivityManager)
            getSystemService(Context.CONNECTIVITY_SERVICE);

    // Get details on the currently active default data network
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    // If there is a network connection, fetch data
    if (networkInfo != null && networkInfo.isConnected()) {
        // Get a reference to the LoaderManager, in order to interact with loaders.
        LoaderManager loaderManager = getLoaderManager();

        // Initialize the loader. Pass in the int ID constant defined above and pass in null for
        // the bundle. Pass in this activity for the LoaderCallbacks parameter (which is valid
        // because this activity implements the LoaderCallbacks interface).
        loaderManager.initLoader(EARTHQUAKE_LOADER_ID, null, this);
    } else {
        // Otherwise, display error
        // First, hide loading indicator so error message will be visible
        View loadingIndicator = findViewById(R.id.loading_indicator);
        loadingIndicator.setVisibility(View.GONE);

        // Update empty state with no connection error message
        mEmptyStateTextView.setText(R.string.no_internet_connection);
    }
}

@Override
public Loader<List<Earthquake>> onCreateLoader(int i, Bundle bundle) {
    // Create a new loader for the given URL
    return new EarthquakeLoader(this, USGS_REQUEST_URL);
}

@Override
public void onLoadFinished(Loader<List<Earthquake>> loader, List<Earthquake> earthquakes) {
    // Hide loading indicator because the data has been loaded
    View loadingIndicator = findViewById(R.id.loading_indicator);
    loadingIndicator.setVisibility(View.GONE);

    // Set empty state text to display "No earthquakes found."
    mEmptyStateTextView.setText(R.string.no_earthquakes);

    // Clear the adapter of previous earthquake data
    mAdapter.clear();

    // If there is a valid list of {@link Earthquake}s, then add them to the adapter's
    // data set. This will trigger the ListView to update.
    if (earthquakes != null && !earthquakes.isEmpty()) {
        mAdapter.addAll(earthquakes);
    }
}

@Override
public void onLoaderReset(Loader<List<Earthquake>> loader) {
    // Loader reset, so we can clear out our existing data.
    mAdapter.clear();
}

}

i'm making an app in which you can view quotes and if u like any of the quote, you can press the star button and it will copy into another fragment named favorite. The quotes itself are written in different fragments and not in main activity. Can anyone help me with it?

Here is my MainActivity

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    android.app.FragmentManager fragmentManager = getFragmentManager();

    if (id == R.id.nav_first_layout) {
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame,new FirstFragment())
                .commit();
    } else if (id == R.id.nav_second_layout) {
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame,new SecondFragment())
                .commit();

    } else if (id == R.id.nav_third_layout) {
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame, new ThirdFragment())
                .commit();
    }else if(id ==R.id.nav_favorites) {
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame, new favorites())
                .commit();
    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}}

and This is my fragment code

package com.example.nouma.life;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

/**
 * Created by nouma on 28-08-2016.
 */
public class FirstFragment extends Fragment {
    View myView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        myView=inflater.inflate(R.layout.first_layout,container,false);
        return myView;
    }
}

and this is my fragment XML

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:clickable="false">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Stop acting so small. You are the universe in ecstatic motion"
            android:textColor="#939393"
            android:textSize="20dp"
            android:fontFamily="sans-serif-light"
            android:textIsSelectable="true"
            android:background="#212121"
            android:letterSpacing="0.1"
            android:id="@+id/t3"/>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="50dp"
            android:background="#F9A825">

            <ToggleButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/toggleButton"
                android:background="#F9A825"
                android:textOn="★"
                android:textOff="☆"
                android:textSize="20dp"
                android:textColor="#FFFFFF"
                android:layout_gravity="left"/>
        </LinearLayout>



        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="When you do things from your soul, you feel a river moving in you, a joy."
            android:textColor="#939393"
            android:textSize="20dp"
            android:fontFamily="sans-serif-light"
            android:textIsSelectable="true"
            android:background="#212121"
            android:letterSpacing="0.1"
            android:id="@+id/t4"/>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="50dp"
            android:background="#F9A825">

            <ToggleButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/toggleButton1"
                android:background="#F9A825"
                android:textOn="★"
                android:textOff="☆"
                android:textColor="#FFFFFF"
                android:textSize="20dp"
                android:layout_gravity="left"/>
        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Yesterday I was clever, so I wanted to change the world. Today I am wise, so I am changing myself"
            android:textColor="#939393"
            android:textSize="20dp"
            android:fontFamily="sans-serif-light"
            android:textIsSelectable="true"
            android:background="#212121"
            android:letterSpacing="0.1"
            android:id="@+id/t5"/>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="50dp"
            android:background="#F9A825">

            <ToggleButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/toggleButton2"
                android:background="#F9A825"
                android:textOn="★"
                android:textOff="☆"
                android:textSize="20dp"
                android:textColor="#FFFFFF"
                android:layout_gravity="left"/>
        </LinearLayout>

    </LinearLayout>
</ScrollView>

I'm very new to fragments and overall java programming i even trid this link https://developer.android.com/training/basics/fragments/communicating.html but culdnt gt my answer.

I've got two activities:

  1. Main(with all logic and fragments)
  2. SearchActivity.

One of the Main's fragment calls getActivity().onSearchRequested().

SearchActivity catches the query and represents recived data in recycler.

Now I want to return selected item from recycler to that fragment, but I can't understand how to do that if startActivityForResult() wasn't called?

I have downloaded a sample project from AWS Mobile Hub with SNS push services integrated with it.

In my existing app, I copied the com.amazonaws.mobile package into my application java directory. In addition, I've added the AWS gradle libraries into my gradle file of the module, and added the meta-data and receiver attributes into my manifest file.

In my MainActivity.java I have this code:

import com.amazonaws.mobile.AWSMobileClient;
import com.amazonaws.mobile.push.PushManager;

private PushManager pushManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    pushManager = AWSMobileClient.defaultMobileClient().getPushManager();
    toggleNotification(true);
}

The toggleNotification method is taken from the demo app. The problematic part is the line where I initialize pushManager (pushManager = AWSMobileClient...). Here is the log:

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: com.intap.snspushtest, PID: 25796
                                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.intap.snspushtest/com.intap.snspushtest.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.amazonaws.mobile.push.PushManager com.amazonaws.mobile.AWSMobileClient.getPushManager()' on a null object reference
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                                                                       at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:158)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.amazonaws.mobile.push.PushManager com.amazonaws.mobile.AWSMobileClient.getPushManager()' on a null object reference
                                                                       at com.intap.snspushtest.MainActivity.onCreate(MainActivity.java:29)
                                                                       at android.app.Activity.performCreate(Activity.java:6876)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                       at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                       at android.os.Looper.loop(Looper.java:158) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

It says that getPushManager() is a null object reference, which is weird, since in the sample application it works great, and I didn't change anything on the copied files...

Could you please help me with that? I'm still trying to figure out why is it null...

Despite checking many questions in stackoverflow and google, i could not find the solution to this problem.

Can someone post and explain a sample code how to use parcelable in Android with multiple data and how it will be passed and displayed in an xml layout with loop.

E.g. for Restaurant Activity, it will pass and display the below items to Restaurant Menu Activity.

  1. Restaurant Name
  2. Restaurant Address
  3. Restaurant Menu Category ("American Breakfast")
    • American Breakfast 1, American Breakfast 2, American Breakfast 3...
  4. Restaurant Menu Category ("Waffles")
    • Waffles 1, Waffles 2, Waffles 3 etc...

and so the category and the food items continues...

Thanks!

Hello i am beginner in Android programming and i want to use navigation drawer in my app, and i dont want to use premaded from android studio. I have some TextViews in that and i want add box (some space) with image and textview like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
        <ImageView
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:id="@+id/drawerImage"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/drawerNickname"/>
</LinearLayout>

Over the list of TextViews. But if i try it, the image and text is not in drawer but in normal screen (sorry for bad english).

My XML for navigation drawer is:

<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.lika85456.csgoadskinsv2.PlayActivity">
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
        <ImageView
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:id="@+id/drawerImage"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/drawerNickname"/>
        </LinearLayout>


    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="@color/drawerBackground"/>
</android.support.v4.widget.DrawerLayout>

Actually my service is running pretty well as I expected. I know this because I start a test thread in the onStartCommand function to output a test string to the console every 3 seconds. The console of android studio is printing the test string after more than 40 minutes since it started whereas the activity that started the service has already been killed by the system. However, the socket in another thread in the service does not sustain that long. I create a tcp socket to receive audio data in the service and call its getinputstream in a while(true) loop to check if there is audio data coming in to play. The socket works fine if it keeps receiving something to play. But if getinputstream does not receive any data over about 20 minutes, it turns out closed or it just throws an exception and will not receive any coming data. In the same time, the test thread just still prints out the test string every 3 seconds. Any one knows what wrong is with the socket? Why it disconnects to the server after 20 minutes if it gets no input stream while the service contains it is still working fine.Any help will be much appreciated.

I want to add share link in my app including the downloading link of android play. But since my app is not launched, I dont have download link currently. How can I include download link now?

Below is my JSON data , but am migrating to Firebase to help me retrive the data, how can I format my Firebase Database data like this JSON. Am stuck in this , its quite confusing to me. How can I specify objects. Like my JSON below.

[
  {
    "DoctorsName": "DR.LUTAAYA HUZAIFAH IDRIS",
    "HealthCentreName": "Mulago",
    "Specialisation": "Dentist",
    "Information": "am genious",
    "photo": "huzaifah.jpg",
    "WorkingHours": "8:00am - 3:00pm",
    "PhoneNumber": "0704594180",
    "Email": "huxaiphaeridris@gmail.com"
  },
  {
    "DoctorsName": "DR. G. WABULEMBO",
    "HealthCentreName": "Kibuli",
    "Specialisation": "Opthalmologist",
    "Information": " is a consultant Opthalmologist with over 25 years experience in Canada and Uganda.",
    "photo": "wabulembo.jpg",
    "WorkingHours": "8:00am - 12:00pm",
    "PhoneNumber": "0756478923",
    "Email": "wabulembo@gmail.com"
  },
  {
    "DoctorsName": "DR. BUKIRWA JAUHARAH",
    "HealthCentreName": "Kibuli",
    "Specialisation": "Urologist",
    "Information": "Shes a Urologist , she has an experience of 7 years in Kibuli Hospital , and she studied in the United States Of America University",
    "photo": "jauharah.jpg",
    "WorkingHours": "10:00am - 4:00pm",
    "PhoneNumber": "0706081457",
    "Email": "bukijauha@gmail.com"
  },
  {
    "DoctorsName": "DR. R. SEKITOLEKO",
    "HealthCentreName": "Nakasero Hospital",
    "Specialisation": "General Physician",
    "Information": " is consultant physician with over 33 years of experience in Berlin and Hamburg (Germany) and Mulago Hospital (Uganda). He also practised as a consultant with WHO (2001-2003).",
    "photo": "sekitoleko.jpg",
    "WorkingHours": "12:00am - 7:00pm",
    "PhoneNumber": "0765633667",
    "Email": "sekitoleko@gmail.com"
  },
  {
    "DoctorsName": "DR. A. MAKHOBA ",
    "HealthCentreName": "Nakasero Hospital",
    "Specialisation": "Cardiologist",
    "Information": "is a consultant cardiologist,. He has practised for more than 20 years in Illinois and Wisconsin (USA) and for over two years in Uganda, at the Uganda Heart Institute and Nakasero Hospital.",
    "photo": "makhoba.jpg",
    "WorkingHours": "8:00am- 4:00pm",
    "PhoneNumber": "0765453636",
    "Email": "makhoba@gmail.com"
  },
  {
    "DoctorsName": "DR.Sako Banabus",
    "HealthCentreName": "Nakasero Hospital",
    "Specialisation": "Dentist",
    "Information": null,
    "photo": "kamanzi.jpg",
    "WorkingHours": "7:00pm - 3:00am",
    "PhoneNumber": "0754369696",
    "Email": "sw@gmail.com"
  },
  {
    "DoctorsName": "DR. KAMANZI ABUBAKAR",
    "HealthCentreName": "Mengo Hosiptal",
    "Specialisation": "Neurosurgeon",
    "Information": "Hes a Neurosurgeon, he has an experience of 20 years in Mengo Hospital , he studied in the Carlifornia University",
    "photo": "kamanzi.jpg",
    "WorkingHours": "7:00pm - 3:00am",
    "PhoneNumber": "07003014850",
    "Email": "kamanziabubakar75@gmail.com"
  }
]

So I have tried this one tutorial which tells how the gestures work and I made a simple activity which detects the gesture and generates a toast. Now I am working on my project and made my homepage which has a simple Relative layout and an image view. The gestures work find there as well. Now I made a new Help page and tried everything I could but the gesture is not working for me. Is it because of the layout? as this one contains multiple relative and linear layouts. Given below is my Help activity. I wanna open speech recognition on LongPress (I am trying a toast here but its not working) Any help would be appreciated. I may be missing out something stupid

   package com.example.dell.optasia;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaPlayer;
import android.speech.tts.TextToSpeech;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import static android.view.GestureDetector.*;
import org.w3c.dom.Text;

import java.util.List;

public class Help extends AppCompatActivity implements
        OnGestureListener, OnDoubleTapListener {
    private GestureDetectorCompat GestureDetect;
    public MediaPlayer mp1;
    TextView textView;
    TextView answer5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);
        mp1 = MediaPlayer.create(Help.this, R.raw.help);
        mp1.start();
        ActionBar ab = getSupportActionBar(); //Actionbar
        ab.setLogo(R.mipmap.iconlaunch);
        ab.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // set your desired color

        ab.setDisplayUseLogoEnabled(true); //shows logo
        ab.setDisplayShowHomeEnabled(true); //shows home page
        TextView textView= (TextView) findViewById(R.id.textView);

        GestureDetect = new GestureDetectorCompat(this, this);
        GestureDetect.setOnDoubleTapListener(this);

        TextView txtview = (TextView) findViewById(R.id.question1);
        final TextView answer1 = (TextView) findViewById(R.id.answer1);

                txtview.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v) {
                        if (answer1.getVisibility() == View.VISIBLE)
                            answer1.setVisibility(View.GONE);
                        else
                        answer1.setVisibility(View.VISIBLE);
                    }

                });

        TextView txtview1 = (TextView) findViewById(R.id.question2);
        final TextView answer2 = (TextView) findViewById(R.id.answer2);
                txtview1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v){
                        if (answer2.getVisibility() == View.VISIBLE)
                            answer2.setVisibility(View.GONE);
                        else
                            answer2.setVisibility(View.VISIBLE);
                        }
                });
        TextView txtview2 = (TextView) findViewById(R.id.question3);
        final TextView answer3 = (TextView) findViewById(R.id.answer3);
                txtview2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (answer3.getVisibility() == View.VISIBLE)
                            answer3.setVisibility(View.GONE);
                        else
                        answer3.setVisibility(View.VISIBLE);
                    }
                });
        TextView txtview3 = (TextView) findViewById(R.id.question4);
        final TextView answer4 = (TextView) findViewById(R.id.answer4);

        txtview3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (answer4.getVisibility() == View.VISIBLE)
                            answer4.setVisibility(View.GONE);
                        else
                        answer4.setVisibility(View.VISIBLE);
                    }
                });

        TextView txtview4 = (TextView) findViewById(R.id.question5);
        final TextView answer5 = (TextView) findViewById(R.id.answer5);
                txtview4.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (answer5.getVisibility() == View.VISIBLE)
                            answer5.setVisibility(View.GONE);
                        else
                        answer5.setVisibility(View.VISIBLE);
                    }
                });



    }

    //for the overflow actionbar

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.main_activity_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    //for the actionbar menu items
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.Play_ID:
                mp1 = MediaPlayer.create(Help.this, R.raw.manual);
                mp1.start();
                break;
            case R.id.Help_ID:
                startActivity(new Intent(Help.this, Help.class));
                break;
            case R.id.About_ID: {
                startActivity(new Intent(Help.this, LocationMain.class));
                return true;
            }
            case R.id.Contact_Us:{
                startActivity(new Intent(Help.this, ContactUs.class));
                return true;
            }
            case android.R.id.home:{
                startActivity(new Intent(Help.this, HomeScreen.class));
                return true;
            }
            default:
                return super.onOptionsItemSelected(item);
        }
        return false;
    }
    //calls event for the gestures
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        GestureDetect.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
    @Override
    public boolean onDoubleTap(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent motionEvent) {
        if(mp1!=null)
        {
            mp1.stop();
        } return false;
    }

    @Override
    public boolean onDown(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent motionEvent) {

        Toast.makeText(Help.this, "longpress!", Toast.LENGTH_LONG).show();

    }

    @Override
    public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        return false;
    }

}

I have a simple SQLite database that is a table of winners in a card game. The table has columns for the unique ID, name, score, date and a set of data which will be used later (a string array). I'm able to query from and render the data into a listview (which was much harder to figure out than I expected). Now, I want to click on an item in the listview to launch another activity using the data from the string array. However, when I go into the onItemClick method, getItem always returns null. Here's the class:

    public class NewHoFListViewActivity extends Activity {

    DBHelper dbHelper;
    Cursor cursor;
    NewHoFListAdapter ListAdapter ;

    ArrayList<String> ID_ArrayList = new ArrayList<>();
    ArrayList<String> nameArrayList = new ArrayList<>();
    ArrayList<String> scoreArrayList = new ArrayList<>();
    ArrayList<String> dateArrayList = new ArrayList<>();
    ListView myListView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_hof_list_view);

        myListView = (ListView) findViewById(R.id.listView1);

        dbHelper = new DBHelper(this);

        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                                    long id) {

                String item = (String) parent.getAdapter().getItem(position);

                // Get the cursor, positioned to the corresponding row in the result set
                //Cursor cursor = (Cursor) myListView.getItemAtPosition(position);

                // Get the data from this row in the database.
                //String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
                Toast.makeText(getApplicationContext(),
                        item, Toast.LENGTH_SHORT).show();

            }
        });

    }

    @Override
    protected void onResume() {

        ShowSQLiteDBdata() ;

        super.onResume();
    }

    private void ShowSQLiteDBdata() {



        ID_ArrayList.clear();
        nameArrayList.clear();
        scoreArrayList.clear();
        dateArrayList.clear();

        cursor = dbHelper.getWritableDatabase().rawQuery("SELECT * FROM winners", null);

        if (cursor.moveToFirst()) {
            do {
                ID_ArrayList.add(cursor.getString(cursor.getColumnIndex(DBHelper.WINNERS_COLUMN_ID)));

                nameArrayList.add(cursor.getString(cursor.getColumnIndex(DBHelper.WINNERS_COLUMN_NAME)));

                scoreArrayList.add(cursor.getString(cursor.getColumnIndex(DBHelper.WINNERS_COLUMN_SCORE)));

                dateArrayList.add(cursor.getString(cursor.getColumnIndex(DBHelper.WINNERS_COLUMN_DATE)));

            } while (cursor.moveToNext());
        }

        ListAdapter = new NewHoFListAdapter(NewHoFListViewActivity.this,

                ID_ArrayList,
                nameArrayList,
                scoreArrayList,
                dateArrayList

        );

        myListView.setAdapter(ListAdapter);

        cursor.close();
    }

}

I've left in the other approach I've tried (commented out); both return null. Any help would be appreciated!

What should I take into account when combining 2 separate java file with 2 onCreate function?

For example, I've a java for play and pause audio while the other 1 is for recording audio which are separately coded.

What is the right approach should I take to arrange the code and make them a java with both function?

Thank you.

I want to create an npm module (for iOS only now) that uses another iOS SDK. What is the way to do this? Any pointers or examples would be helpful. I am working on developing one, but running into library dependency issues while development and compilation time for obvious reasons.

After the transition to swift 3, this logic previously used in swift 2.xx to create a bottom border to my UITextField doesn't work:

  let border = CALayer()
  border.frame = CGRect(x: 0.0, y: myTextField.frame.size.height - 4, width: myTextField.frame.size.width, height: 1.0);
  border.backgroundColor = UIColor.black.cgColor
  myTextField.layer.addSublayer(border)

After examining the api doc's, i can't seem to find a reason why this doesn't work. any suggestions?

After seeing the video here, i got confused about the use of final keyword.

Here below is an example image from the video

enter image description here

Here there are two classes Pet as parent class and Dog as child class, and we have function implementation of makeNoise(p) which takes Pet instance as parameter. But behind the scene compiler inserts few more lines to this method for checking class.

Since makeNoise(p) takes parameter as Pet instance, compiler should directly call the property "name" from the Pet class, as the method parameter is for this class.

Why would compiler be worried about the overriding the property in child class, because the parameter is a Pet instance and compiler knows it. isn't it?

My question may looks silly but if someone can explain it more clearly, i would appreciate it.

I'd like to use mp4s interspersed with text on my blog, like gifs. iOS 10 now allows the playsinline attribute on video tags, which works great.

However, when another video comes into the viewport and starts playing it pauses any other video. On the iPad this is confusing because there are often more than one video elements visible.

I've added a click handler to play a video when it is tapped. In this case too, playing one video pauses the others. Is there any way to play more than one video at a time in iOS Safari / Webkit?

I have the code where I get the user's location

 import UIKit
 import MapKit
 import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate,MKMapViewDelegate {

@IBOutlet weak var map : MKMapView!


var locationManager = CLLocationManager()

override func viewDidLoad()
{
    super.viewDidLoad()

    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.startUpdatingLocation()



}
override func viewDidAppear(animated: Bool) {
    map.showsUserLocation = true

}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    let location = locations.last
    let center = CLLocationCoordinate2D(latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!)
    let region = MKCoordinateRegion(center : center , span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))

    self.map.setRegion(region, animated: true)
    self.locationManager.stopUpdatingLocation()

}


func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    print("cantt find")
}

}

now I want to make a button for the user to click on then the location should be saved. The idea of the app is to show a button on another View Controller that will take the user to the saved location when he/she clicked on it( pin would be really helpful). Can someone guide me.

I'm trying to make a custom cropping user can make for an image. For example selecting a head of the user selfie (not just the face). So all background would be removed and just the head and hair would be there.

I saw many apps has this interface where you mark with green the parts you want and red the parts you want removed from the image. I'm pretty sure I saw this somewhere as open source. Does anyone could help me find something like that or suggest a method to do that?

The only think I found is a Mac source (it is a good example of what I'm willing to create):

https://github.com/void-main/VMBrushImageView

The following code has a video being played. But the video starts immediately when the view controller is launch. When the view controller is launch I would like the user to hit the play button for the video to play. Now the video plays as soon as the view controller is launched.

 let path = NSBundle.mainBundle().pathForResource("x", ofType:"mp4")
    let url = NSURL.fileURLWithPath(path!)
    self.moviePlayer = MPMoviePlayerController(contentURL: url)
    if let player = self.moviePlayer {
        player.view.frame = CGRect(x: 55, y: 75, width: self.view.frame.size.width/2, height: self.view.frame.size.height / 5)
        player.view.sizeToFit()
        player.scalingMode = MPMovieScalingMode.AspectFit
        player.fullscreen = false
        player.controlStyle = MPMovieControlStyle.Default
        player.movieSourceType = MPMovieSourceType.File
        player.repeatMode = MPMovieRepeatMode.One
        player.play()
        self.view.addSubview(player.view)