Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
P

Pavlex4

@Pavlex4
About
Posts
142
Topics
33
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Android chat application message notification receive issue
    P Pavlex4

    I have created android chat application. When I send message it loops all messages through notification and then show the latest message instead of just showing newest message inside the notification!!!! How to fix this issue???

    public class Chat extends AppCompatActivity
    {
    LinearLayout layout;
    RelativeLayout layout_2;
    ImageView sendButton;
    EditText messageArea;
    ScrollView scrollView;
    Firebase reference1, reference2;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_chat);
    
        layout = (LinearLayout) findViewById(R.id.layout1);
        layout\_2 = (RelativeLayout)findViewById(R.id.layout2);
        sendButton = (ImageView)findViewById(R.id.sendButton);
        messageArea = (EditText)findViewById(R.id.messageArea);
        scrollView = (ScrollView)findViewById(R.id.scrollView);
    
        Firebase.setAndroidContext(this);
    
        reference1 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.username + "\_" + UserDetails.chatWith);
        reference2 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.chatWith + "\_" + UserDetails.username);
    
        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String messageText = messageArea.getText().toString();
    
                if(!messageText.equals("")){
                    Map map = new HashMap();
                    map.put("message", messageText);
                    map.put("user", UserDetails.username);
                    reference1.push().setValue(map);
                    reference2.push().setValue(map);
                    messageArea.setText("");
                }
            }
        });
    
        reference1.addChildEventListener(new ChildEventListener()
        {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    
                for (DataSnapshot child: dataSnapshot.getChildren())
                {
                    Map map = dataSnapshot.getValue(Map.class);
                    String message = map.get("message").toString();
                    String userName = map.get("user").toString();
    
                    if (userName.equals(UserDetails.username))
                    {
                        addMessageBox("You:-\\n" + message, 1);
    
    Android help android com tutorial question

  • Android media player won't start
    P Pavlex4

    I have fixed the problem! Radio didn't work because I forgot to add http:// in ip address after reading it from url !!!

    Android android announcement

  • Android media player won't start
    P Pavlex4

    I have created android application to stream online radio stations but when I click start button to play radio it won't start.In service I read ip address of file from url and add it to string.When user selects radio station I add port to string with ip address.

    public class BackgroundService extends Service implements OnCompletionListener
    {
    MediaPlayer mediaPlayer;
    private String STREAM_URL;
    final String textSource = "http://audiophileradio.stream/Ip.txt";

        @Override
        public IBinder onBind(Intent intent) {
            return null;
        }
    
        @Override
        public void onCreate()
        {
    
        }
    
        @Override
        public int onStartCommand(Intent intent, int flags, int startId)
        {
            new MyTask().execute();
    
            return START\_STICKY;
        }
    
        public void onDestroy() {
            if (mediaPlayer.isPlaying()) {
                mediaPlayer.stop();
            }
            mediaPlayer.release();
        }
    
        public void onCompletion(MediaPlayer \_mediaPlayer) {
            stopSelf();
        }
    
    
        @Override
        public boolean onUnbind(Intent intent)
        {
            return super.onUnbind(intent);
        }
    
        private class MyTask extends AsyncTask
        {
            String textResult;
    
            @Override
            protected String doInBackground(Void... params) {
    
                URL textUrl;
    
                try {
                    textUrl = new URL(textSource);
    
                    BufferedReader bufferReader
                            = new BufferedReader(new InputStreamReader(textUrl.openStream()));
    
                    String StringBuffer;
                    String stringText = "";
                    while ((StringBuffer = bufferReader.readLine()) != null) {
                        stringText += StringBuffer;
                    }
                    bufferReader.close();
    
                    textResult = stringText;
                    return textResult;
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                    textResult = e.toString();
                } catch (IOException e) {
                    e.printStackTrace();
                    textResult = e.toString();
                }
    
                return null;
    
            }
    
            @Override
            protected void onPostExecute(String resul
    
    Android android announcement

  • Android read file from url
    P Pavlex4

    I created android application to stream online radio stations but it doesn't work.I want to read ip address from url and assign it to string and when user selects radio to listen I should add port to that string!!!

    public class BackgroundService extends Service implements OnCompletionListener
    {
    MediaPlayer mediaPlayer;
    private String STREAM_URL;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    
    @Override
    public void onCreate()
    {
        final StringBuilder text = new StringBuilder();
    
        new Thread(new Runnable()
        {
            public void run()
            {
                try
                {
                    URL url = new URL("http://audiophileradio.stream/Ip.txt");
    
                    HttpURLConnection conn=(HttpURLConnection) url.openConnection();
    
                    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    String str;
                    while ((str = in.readLine()) != null)
                    {
                        text.append(str);                      
                    }
                    in.close();
                    text.insert(text.length(), ":8000");
                }
                catch (Exception e)
                {
                    Log.d("MyTag",e.toString());
                }
            }
        }).start();
    

    SharedPreferences sharedPreferences =
    PreferenceManager.getDefaultSharedPreferences(this);
    String radio = sharedPreferences.getString("station", "8000");

        if (radio != null && radio.equals("8000"))
        {
            text.append(":8000");
            STREAM\_URL = text.toString();
            Toast.makeText(this,STREAM\_URL,Toast.LENGTH\_SHORT).show();
        }
        if (radio != null && radio.equals("8010"))
        {
            text.append(":8010");
            STREAM\_URL = text.toString();
        }
        if (radio != null && radio.equals("8020"))
        {
            text.append(":8020");
            STREAM\_URL = text.toString();
        }
        if (radio != null && radio.equals("8030"))
        {
            text.append(":8030");
            STREAM\_URL = text.toString();
        }
    
        mediaPlayer = new MediaPlayer();
        try
        {
            mediaPlayer.setDataSource(STREAM\_URL);
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    
        mediaPlayer.setOnCo
    
    Android android

  • Previous fragment visible under the new fragment issue
    P Pavlex4

    I have created android application with navigation drawer and when I click item from navigation drawer old fragment is not replaced,I can still see the old fragment under the new fragment.How to fix this issue?

    private void displaySelectedScreen(int id)
    {
    Fragment fragment = null;

            switch (id)
            {
                case R.id.home:
                    fragment = new Main();
                    break;
                case R.id.settings:
                    Intent intent = new Intent(this, Settings.class);
                    startActivity(intent);
                    break;
                case R.id.about:
                    Intent intent1 = new Intent(this, About.class);
                    startActivity(intent1);
                    break;
                case R.id.share:
                    try
                    {
                        Intent i = new Intent(Intent.ACTION\_SEND);
                        i.setType("text/plain");
                        i.putExtra(Intent.EXTRA\_SUBJECT, "Audiophileradio");
                        String sAux = "\\nLet me recommend you this application\\n\\n";
                        sAux = sAux + "https://play.google.com/store/apps/details?id=Orion.Soft \\n\\n";
                        i.putExtra(Intent.EXTRA\_TEXT, sAux);
                        startActivity(Intent.createChooser(i, "choose one"));
                    }
                    catch(Exception e)
                    {
                        //e.toString();
                    }
                    break;
                case R.id.send:
                    fragment = new Feedback();
                    break;
            }
            if (fragment != null)
            {
                FragmentManager fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.contentFrame, fragment).commit();
            }
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer\_layout);
            drawer.closeDrawer(GravityCompat.START);
        }
    
        @SuppressWarnings("StatementWithEmptyBody")
        @Override
        public boolean onNavigationItemSelected(MenuItem item)
        {
            // Handle navigation view item clicks here.
            int id = item.getItemId();
    
            displaySelectedScreen(id);
    
            return true;
        }
    

    content_main.xml

    Android help android com beta-testing xml

  • C# Read random line
    P Pavlex4

    He told me to change to this format text file:

    Planete i njihovi sateliti|Zemlja=Mesec|Mars=Fobos|Jupiter=Io|Saturn=Titan|Uran=Titania|Neptun=Triton|Pluton=Haron|Merkur=Nema satelit
    Čuveni parovi iz umetnosti|Hamlet=Ofelija|Ruslan=Ljudmila|Zevs=Hera|Otelo=Dezdemona|Paris=Helena|Abelard=Eloiza|Paolo=Frančeska|Lanselot=Ginevra
    ...

    When I change to that format I cannot add lines starting with * to list!!!

    C# csharp question linq graphics tutorial

  • C# Read random line
    P Pavlex4

    I have added questions and answer to list!How to get random question with it's answers from the list?

    string[] data = File.ReadAllLines("spojnice1.txt");
    List questions = new List();
    foreach (string line in data)
    questions.Add(line);

    C# csharp question linq graphics tutorial

  • C# Read random line
    P Pavlex4

    How to change format? My text file has 15000 lines!!!!

    C# csharp question linq graphics tutorial

  • C# Read random line
    P Pavlex4

    How to read random line from text file that startswith * and lines below him that are related to him? I have created to get random line with question using commands below, but after that it doesn't read lines below him that are related to him,instead of that he read lines from beggining!!! var questions = File.ReadLines(filePath) .Where(line => line.StartsWith("*")).ToList(); var rng = new Random(); var myRandomQuestion = questions[rng.Next(questions.Count)].Substring(1); label1.Text = myRandomQuestion; My text file has 15000 lines.Lines with * character are questions and lines below them are terms relating to that question. This is one part of file: *Planete i njihovi sateliti Zemlja=Mesec Mars=Fobos Jupiter=Io Saturn=Titan Uran=Titania Neptun=Triton Pluton=Haron Merkur=Nema satelit *Čuveni parovi iz umetnosti Hamlet=Ofelija Ruslan=Ljudmila Zevs=Hera Otelo=Dezdemona Paris=Helena Abelard=Eloiza Paolo=Frančeska Lanselot=Ginevra *Latinski pojmovi Kvalifikacija=Osposobljenost Karantin=Izolacija Radijacija=Zračenje Ratifikacija=Potpisivanje Racionalan=Razuman Reakcija=Otpor Realizacija=Ostvarenje Rekapitulacija=Ponavljanje *Poveži aktuelne predsednike sa državama u kojima vladaju. Trajan Basesku=Rumunija Karolos Papuljas=Grčka Đorđo Napolitano=Italija Tomas Hendrik Ilves=Estonija Danilo Tirk=Slovenija Dimitris Hristofias=Kipar Tarja Halonen=Finska Meri Mekelis=Irska *Francuski gradovi Bordeaux=Bordo Auxerre=Okser Toulouse=Tuluz Nantes=Nant Marseille=Marselj Dijon=Dižon Limoges=Limož Chateauroux=Šatero

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    using System.Collections.Specialized;
    using System.IO;

    namespace Slagalica
    {
    public partial class Spojnice : MetroFramework.Forms.MetroForm
    {
    public Spojnice()
    {
    InitializeComponent();
    }

        string igra;
        int j = 0;
        Button\[\] button;
        private void Spojnice\_Load(object sender, EventArgs e)
        {
            Random r = new Random();
            int indeks;
            igra = "spojnice";
            StreamReader sr = new StreamReader(igra + ".txt");
            string\[\] niz1 = new string\[8\];
            string\[\] niz2 = new string\[8\];
    
            //label1.Text = sr.ReadLine();
    
            var q
    
    C# csharp question linq graphics tutorial

  • Android Day of Week Calculator
    P Pavlex4

    I added date = new Date(); to button onclicklistener but when I click button inside app it gets pressed and stays like that and nothing happens!!!

    button.setOnClickListener(new View.OnClickListener()
    {
    @Override
    public void onClick(View view)
    {
    String dayOfWeek;
    boolean isValid;

                **date = new Date();**
    
                Calendar c = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd\_HHmmss");
                String strDate = sdf.format(c.getTime());
    
    Android android question

  • Android Day of Week Calculator
    P Pavlex4

    What is problem with that line?

    Android android question

  • Android Day of Week Calculator
    P Pavlex4

    You mean this "private Date date;" ?

    Android android question

  • Android Day of Week Calculator
    P Pavlex4

    So,what should I do?

    Android android question

  • Android Day of Week Calculator
    P Pavlex4

    I have initialized Date date = new Date(); but now I get application has stopped working and error is still in the same line!!!

    try
    {
    Date date = new Date();
    String getdate = spinner.getItemAtPosition(position).toString() + value
    + textView2.getText().toString();
    date = sdf.parse(getdate);
    } catch (ParseException ex)
    {
    // handle parsing exception if date string was different from the pattern applying into the SimpleDateFormat contructor
    }
    // isDateValid function call
    isValid = isDateValid(date.getMonth(), date.getDay(), date.getYear());

    Android android question

  • Android Day of Week Calculator
    P Pavlex4

    I have created program that calculates day of week when entered date in format "January 7 2000" .Why do I get NullPointerException exception when I click button to calculate day of week? Here is source code of app:

    public class MainActivity extends AppCompatActivity
    {
    private int position;
    private int value;
    private Button button;
    private EditText editText;
    private TextView textView1,textView2;
    private Spinner spinner,spinner2;
    private ArrayAdapter adapter;

    private boolean isValid;
    private Date date;
    private int inMonth, inDay, inYear;
    
    static boolean isDateValid(int month, int day, int year)
    {
        boolean validation = true;
        int\[\] daysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
        if (month < 1 || month > 12)
        {
            validation = false;
        }
    
        if (day < 1 || day > daysInMonth\[month - 1\])
        {
            validation = false;
        }
    
        if (year < 1700 || year > 3000)
        {
            validation = false;
        }
        return validation;
    }
    
    static String zellerCalc(int month, int day, int year)
    {
        String dayOfWeek;
        int m = -1; 
        int h = -1; 
        int q = day;
        int k;
        int j;
    
        if (month == 1)
        {
            m = 13;
        }
        else if (month == 2)
        {
            m = 14;
        }
        else
        {
            m = month;
        }
    
        if (m == 13 || m == 14)
        {
            year--;
        }
    
        k = year % 100;
        j = year / 100; 
    
        h = (q + (int)((13 \* (m + 1)) / 5.0) + k + (int)(k / 4.0) + (int)(j / 4.0) + (5 \* j)) % 7;
    
        if (h == 0)
        {
            dayOfWeek = "Subota";
        }
        else if (h == 1)
        {
            dayOfWeek = "Nedelja";
        }
        else if (h == 2)
        {
            dayOfWeek = "Ponedeljak";
        }
        else if (h == 3)
        {
            dayOfWeek = "Utorak";
        }
        else if (h == 4)
        {
            dayOfWeek = "Sreda";
        }
        else if (h == 5)
        {
            dayOfWeek = "Četvrtak";
        }
        else
            dayOfWeek = "Petak";
    
        return dayOfWeek;
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_main);
        Too
    
    Android android question

  • Android Day of Week Calculator
    P Pavlex4

    I have created program that calculates day of week when entered date in format "January 7 2000" .Why do I get NullPointerException exception when I click button to calculate day of week? Here is source code of app:

    public class MainActivity extends AppCompatActivity
    {
    private int position;
    private int value;
    private Button button;
    private EditText editText;
    private TextView textView1,textView2;
    private Spinner spinner,spinner2;
    private ArrayAdapter adapter;

    private boolean isValid;
    private Date date;
    private int inMonth, inDay, inYear;
    
    static boolean isDateValid(int month, int day, int year)
    {
        boolean validation = true;
        int\[\] daysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
        if (month < 1 || month > 12)
        {
            validation = false;
        }
    
        if (day < 1 || day > daysInMonth\[month - 1\])
        {
            validation = false;
        }
    
        if (year < 1700 || year > 3000)
        {
            validation = false;
        }
        return validation;
    }
    
    static String zellerCalc(int month, int day, int year)
    {
        String dayOfWeek;
        int m = -1; 
        int h = -1; 
        int q = day;
        int k;
        int j;
    
        if (month == 1)
        {
            m = 13;
        }
        else if (month == 2)
        {
            m = 14;
        }
        else
        {
            m = month;
        }
    
        if (m == 13 || m == 14)
        {
            year--;
        }
    
        k = year % 100;
        j = year / 100; 
    
        h = (q + (int)((13 \* (m + 1)) / 5.0) + k + (int)(k / 4.0) + (int)(j / 4.0) + (5 \* j)) % 7;
    
        if (h == 0)
        {
            dayOfWeek = "Subota";
        }
        else if (h == 1)
        {
            dayOfWeek = "Nedelja";
        }
        else if (h == 2)
        {
            dayOfWeek = "Ponedeljak";
        }
        else if (h == 3)
        {
            dayOfWeek = "Utorak";
        }
        else if (h == 4)
        {
            dayOfWeek = "Sreda";
        }
        else if (h == 5)
        {
            dayOfWeek = "Četvrtak";
        }
        else
            dayOfWeek = "Petak";
    
        return dayOfWeek;
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_main);
        Too
    
    C# android question

  • Android Popup Window
    P Pavlex4

    I have created app that detects otg cable using service. I have created button in action bar with icon,how to make if otg cable is connected hide that button if not connected it should show text and when clicked on it to get popup window with text and animation? MainActivity.class

    public class MainActivity extends AppCompatActivity
    {

    public void startOtgService()
    {
        startService(new Intent(MainActivity.this, OtgService.class));
    
    }
    
    public void stopOtgService()
    {
        stopService(new Intent(MainActivity.this, OtgService.class));
    
    }
    
    @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();
            }
        });
    
        Button startButton = (Button)this.findViewById(R.id.startButton);
        Button stopButton = (Button)this.findViewById(R.id.stopButton);
    
        startButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                startOtgService();
            }
        });
    
        stopButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                stopOtgService();
            }
        });
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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\_set
    
    Android android xml tutorial question

  • Alarm Manager
    P Pavlex4

    I have changed code to this but it still won't show message when cable is connected or disconnected !!!!

    public class MainActivity extends AppCompatActivity
    {
    private Process suProcess;
    private static int conn_length = -1;
    File directory = new File("/sys/bus/usb/devices");
    File[] contents;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_main);
    
        getRoot();
    
    
    
        FileObserver observer = new FileObserver("/sys/bus/usb/devices")
        {
            @Override
            public void onEvent(int event, String file)
            {
                if(event == FileObserver.CREATE)
                {
                    contents = directory.listFiles();
    
                    if (contents.length == conn\_length)
                    {
                        return;
                    }
                    else
                    {
                        conn\_length = contents.length;
                    }
    
                    if (conn\_length == 0)
                    {
    
                        Toast.makeText(MainActivity.this, "otg disconnected", Toast.LENGTH\_SHORT).show();
                    }
                    else
                    {
                        Toast.makeText(MainActivity.this, "otg connected", Toast.LENGTH\_SHORT).show();
                    }
                }
            }
        };
        observer.startWatching();
    }
    
    private void getRoot()
    {
        try
        {
            suProcess = Runtime.getRuntime().exec("su");
        }
        catch (IOException e)
        {
    
        }
    }
    

    }

    Android question

  • Alarm Manager
    P Pavlex4

    Why it's not working?

    public class MainActivity extends AppCompatActivity
    {
    private Process suProcess;
    private static int conn_length = -1;
    File directory = new File("/sys/bus/usb/devices");
    File[] contents = directory.listFiles();

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_main);
    
        getRoot();
    
    
    
        FileObserver observer = new FileObserver("/sys/bus/usb/devices")
        {
            @Override
            public void onEvent(int event, String file)
            {
                if(contents.length == conn\_length){
                    return;
                }
                else{
                    conn\_length = contents.length;
                }
    
                if(conn\_length == 0)
                {
    
                    Toast.makeText(MainActivity.this,"otg not connected",Toast.LENGTH\_SHORT).show();
                }
                else
                {
                    Toast.makeText(MainActivity.this,"otg connected",Toast.LENGTH\_SHORT).show();
                }
            }
        };
        observer.startWatching();
    }
    
    private void getRoot()
    {
        try
        {
            suProcess = Runtime.getRuntime().exec("su");
        }
        catch (IOException e)
        {
    
        }
    }
    

    }

    Android question

  • Alarm Manager
    P Pavlex4

    Than what's the better way to do this?

    Android question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups